Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

javascript - how to change value with Ember.js Array forEach?

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

the item like this: enter image description here

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

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

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

the exception like this

Uncaught TypeError: Object # has no method 'get'

is this item not the Ember's Object?so what the item is?

could someone tell me how to change the 'itme.id's value..

Thanks a million

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the Ember.set(yourObject, propertyName, value); and Ember.get(yourObject, propertyName); to safely set and get properties.

In your case:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...