2

This is how I render the cases ObservableArray in my view

<ListView [items]="cases" class="list-group" *ngIf="cases">
    <ng-template let-case="item">

Say cases has these values:

cases = [{id: 1, name: "Sam"}, {id: 2, name: "Romio"}]

How can I get my ListView to re-render or somehow update the view when I update the first item like this?

cases[0]["name"] = "Michael"

2 Answers 2

3

Have you tried to do apply the change in NgZone? I used this to update an array (not ObservableArray) and the corresponding RadListView automatically was updating.

this.ngZone.run(() => {

        this.dummyService.addFile(this.file).subscribe(
            (fileId) => {
                this.folder.push(this.file);
        },
        (error) => {
           this handleError(error);
        });
     });
Sign up to request clarification or add additional context in comments.

1 Comment

Yesss!! This is the answer, thank you. It works as I want it and with ListView. Although I don't get it why ngZone did the magic!
0

You're going to want to enforce immutability here. So if you must mutate the first object in the array I would. I would try using the spread operator afterward.

cases[0]["name"] = "Michael"
cases = [...cases];

this will set cases to a new instance of an array which should update the list.

1 Comment

I already tried changing the instance but nativescript doesn't re-render the view when you do that until you hit something in the UI. Any action you do is sufficient to re-render. But just changing the instance itself is not enough. Instead of update, I also tried to keep the same instance, and remove the old object and add the new object to the array but with no success. Nothing is re-rendering the view until you do some action to the UI!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.