[英]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.