2013-05-14 57 views
0

奇怪的问题。 我有一个对象数组。这是我的控制器。EmberJS:更新对象内的属性

AmbiantBox.AmbiantsController = Ember.ArrayController.extend({ 
    myArray: [], 
    fillData: function(){ 
    //loop 
     this.myArray.push({index: 0, status: 'hide'}) 
    //loopEnd 
    }, 
    updateState: function(idx){ 
    arr=this.get('myArray'); 
    for(i=0;i<arr.length;++i){ 
    obj=arr[i] 
    if(obj.index==idx){ 
     console.log(idx); 
     obj.set('status','show'); 
     console.log('==========='); 
    }}} 
}); 

我从viewSide调用updateStats函数。 它工作正常,直到我控制参数idx,但代码似乎打破了我设置对象的地方。控制台中也没有错误。

奇怪。任何帮助,将不胜感激。

+0

这是为什么标签的jQuery? –

+0

@Vega:通过jquery调用这个updateState函数。另一个目的是吸引更多的人回答。说实话。 –

+0

@PalashMondal:已经尝试过。这是错误。 未捕获错误:断言失败:您必须使用Ember.set()来访问此属性([object Object]) –

回答

1

如果您想使用Ember的setget's,那么使用Ember.ObjectEmber.Array也是一个好主意。

试试这个:

AmbiantBox.AmbiantsController = Ember.ArrayController.extend({ 
    myArray: Em.A(), 
    fillData: function(){ 
     obj = Ember.Object.create({index: 0, status: 'hide'}); 
     this.myArray.pushObject(obj); 
    }, 
});