lundi 3 août 2015

Ember : How to update a single field in an array of JSON objects in a controller?

How can I update Einstein's score to a 100 in the controller?

In a controller, I have an array of JSON objects like :

items = [
         {title:"John", score:24},
         {title:"Einstein", score:2},
         {title:"Mary", score:19}
        ];

This is rendered in the template using component like this :

{{#each items as |item|}}
  {{some-child-component scoreVal=item.score}}
{{/each}}

What should I do to update Einstein's score to a 100? I just want to change that particular field and have it reflect in the app.

I want to avoid replacing the entire array with a new (almost same one), because that causes a refresh for all components in the template.

[FAILED] I tried using :

var allItems = this.get('items');
allItems[1]['score'] = 100; //ERROR

Also

   this.set('items[1][score]',100); //ERROR




Aucun commentaire:

Enregistrer un commentaire