question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reactive <v-template> inside a ListView

See original GitHub issue

Version

2.3.0

Reproduction link

https://play.nativescript.org/?template=play-vue&id=rUVzXD

Platform and OS info

Both

Steps to reproduce

  1. Run the sample app.
  2. Click on the “Reverse” button
  3. See that the first label is reactive but not the labels inside the <v-template> insider the ListView

What is expected?

The labels inside the ListView should be reactive

What is actually happening?

The labels inside the ListView are not reactive

See the screencast:

listview-reactivity-issue mov

Implementation details

NS Core reactivity is based on its data binding mechanism, which is usually performed in the bindingContext. The NS-vue binding BTW does not make use of this variable, delegating the reactivity to the Vue.js library. This is working in examples like that:

<template>
   ... 
   <Label :text="text" />
   ...
</template>
<script>
export default {
   data: {
      return {
         text: 'Hello world',
      }
   },
   mounted: {
      setTimeout(() => { this.text = 'Bye world' }, 5000);
   }
}
</script>

After 5 seconds, the text Vue data is changed and Vue triggers the logic to know if this change affects to the template, which is the case, and finally calls to the setAttribute('text', 'Bye world') (see implementation), which does the trick changing the NativeScript component attribute.

The problem appears when we change an attribute referenced inside a <v-template> node in a ListView component.

But, why most of the apps are working ok with the ListView? Because we usually change the elements in the list, which is passed in the items attribute, and we have this hack here for refreshing the list:

watch: {
    items: {
      handler(newVal) {
        this.$refs.listView.setAttribute('items', newVal)
        this.refresh()
      },
      deep: true
    }
  },

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

10reactions
VladimirAmiorkovcommented, Oct 1, 2019

This should be addressed as soon as possible. From my understanding it is in the plan for the next major release of nativescript-vue. Currently there are many related issues in both ListView and RadListView which source of this behavior.

1reaction
farfromrefugcommented, May 6, 2022

@msl2000 use an ObservableArray and update items as they get selected/unselected. This is what i do and it is very performant!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble binding ViewModel to View, as part of a ListViewItem ...
I'm having some issues trying to display a view in a ListViewItem Data template in reactive. I have a ListView in, ...
Read more >
ListView ItemTemplate with ReactiveUI ViewModel - Jamil Geor
In this article, we are going to build upon our ListView example by including a DataTemplate for customizing the layout of our ListView...
Read more >
Reactive Forms - ListView - Kendo UI for Angular - Telerik
Utilize the Reactive Angular Forms for data editing in the Angular ... The editing of the ListView in template-driven forms is based on...
Read more >
How to make a responsive layout for listview or template grid?
Hi Maxim. I believe your question is solved in the learning path Mendix Academy - Polish your Styling. I hope this helps you...
Read more >
How to easily deploy the list view formatting templates built by ...
In this post I'm providing a PnP Template that automates the deployment of the templates available on the GitHub repository, a demo environment ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found