如何用Ember.js Array forEach来更改值? [英] how to change value with Ember.js Array forEach?

查看:144
本文介绍了如何用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆