无法访问和修改控制器内的模型数据 [英] Couldn't access and modify model data inside Controller
本文介绍了无法访问和修改控制器内的模型数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过使用Ember的示例程序,如 http://jsbin.com/IyeNucoj/3/edit
I have tried example program using Ember as in http://jsbin.com/IyeNucoj/3/edit
我需要访问和修改一些模型属性,如控件动作中的isSingleLine,isMultiLine,
isPickList。
I need to access and modify some model properties like isSingleLine, isMultiLine, isPickList in controller actions.
它抛出像#Object没有set方法的异常。我找不出
的问题。
It throws exception like #Object doesn't has set method. I couldn't figure out the problem.
例如,
在模板中:
<input type="radio" {{bind-attr checked=item.isSingleLine}}
{{action 'changeBlk1' item}}>
在控制器中:
actions:{
changeBlk1:function(item){
//The following thing is not working. throws exception
item.set('isSingleLine',true);
item.set('isMultiLine',false);
item.set('isPickList',false);
},
changeBlk2:function(item){
},
changeBlk3:function(item){
}
}
推荐答案
您不能使用设置
,因为您的项目似乎都是JavaScript对象,而不是Ember Models。您可以按照此堆栈溢出中的步骤操作使用:
You can't use set
because it appears your items are all JavaScript objects instead of being Ember Models. You can follow the steps in this stack overflow and use:
Ember.set(item, 'isSingleLine', true);
这篇关于无法访问和修改控制器内的模型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文