[英]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');
});
像这样的项目:
如果item.id = 11;
像这样的例外:
断言失败:您必须使用Ember.set()来访问此属性([object Object])
所以item.get('id')或item.set('id',11)
像这样的例外
未捕获的TypeError:对象#没有方法'get'
这个项目不是Ember的对象吗?那么这个项目是什么?
有人能告诉我如何改变'itme.id的价值..
太感谢了
您可以使用Ember.set(yourObject, propertyName, value);
和Ember.get(yourObject, propertyName);
安全地设置和获取属性。
在你的情况下:
self.resultList.forEach(function(item, index, enumerable) {
Ember.set(item, "id", 11);
Ember.get(item, "id");
});
就我而言,我是这样做的
//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); } })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.