如何用Ember.js Array forEach来更改值? [英] how to change value with Ember.js Array forEach?
问题描述
item.id =
item.get('id');
});
这样的项目:
item.id = 11;
这样的异常:
断言失败:您必须使用Ember.set()来访问此属性的
[object Object])
所以item.get('id')或item.set('id' ,11)
这样的异常
未捕获TypeError:Object#has没有方法'get'
这个项目不是Ember的对象,所以这个项目是什么?
有人可以告诉我如何更改'itme.id的值..
感谢百万
您可以使用 Ember.set(yourObject,propertyName,value);
和 Ember.get(yourObject,propertyName);
安全地设置和获取属性。
在您的情况下:
self.resultList.forEach(function(item,index ,枚举){
Ember.set(item,id,11);
Ember.get(item,id);
});
self.resultList.forEach(function(item, index, enumerable){
console.log(self.resultList);
item.id=11;
item.get('id');
});
the item like this:
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
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");
});
这篇关于如何用Ember.js Array forEach来更改值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!