How to change value with Ember.js array for each?

self.resultList.forEach(function(item, index, enumerable){ console.log(self.resultList); item.id=11; item.get('id'); }); 

an element like this: enter image description here

if item.id = 11; an exception like this:

Assertion failed: you must use Ember.set () to access this property (from [object Object])

therefore item.get ('id') or item.set ('id', 11)

exception like this

Uncaught TypeError: Object # does not have a 'get' method

This member is not an Ember? Object. What is an item?

can someone tell me how to change the value of itme.id ..

Thanks a million

+6
source share
2 answers

You can use Ember.set(yourObject, propertyName, value); and Ember.get(yourObject, propertyName); for safe typing and getting properties.

In your case:

 self.resultList.forEach(function(item, index, enumerable) { Ember.set(item, "id", 11); Ember.get(item, "id"); }); 
+21
source

In my case, I did it this way

 //In my controller I've defined the array displayInfoCheckboxes: [ { turnover: { label: "Turnover", value: 1, propertyName: "turnover" } }, { pl: { label: "P&L", value: 1 } } ] //and in my handler I passed the full string path to the property in the set method let displayInfoCheckboxes = this.get('displayInfoCheckboxes'); let controller = this; displayInfoCheckboxes.forEach(function(items,index) { for (var key in items) { controller.set('displayInfoCheckboxes.' + index + '.' + key + '.value', false); } }) 
0
source

Source: https://habr.com/ru/post/950740/


All Articles