直接在控制器上执行的操作处理程序已被弃用 - 以纠正这一点? [英] Action handlers implemented directly on controllers are deprecated -how to correct this?
本文介绍了直接在控制器上执行的操作处理程序已被弃用 - 以纠正这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
直接在控制器上实现的动作处理程序已被弃用
{{input class =firstName type =textplaceholder =first namevalue = firstName}}
{{input class =lastNametype =textplaceholder =last namevalue = lastName}}
< button class =submit{{action addPerson}}>添加< / button>
< br />
< table>
{{#each person in controller}}
< tr>
< td class =name> {{person.fullName}}< / td>
< td>< button class =delete{{action deletePerson person}}>删除< / button>< / td>
< / tr>
{{/ each}}
< / table>
如何修改上述模板以更正?
解决方案
看起来我只需要给PR 看起来改变了这一点:)
在我的控制器中,我只需要像这样的操作移动addPerson / deletePerson
App.PeopleController = Ember.ArrayController.extend({
actions:{
addPerson:function(){
var person = {
firstName:this.get('firstName'),
lastName:this.get('lastName')
};
App.Person.add(person);
},
deletePerson:function(person){
App.Person.remove(person);
}
}
});
I just upgraded from ember.js RC7 to RC8 and found that a simple template (shown below) would throw a deprecated warning
"Action handlers implemented directly on controllers are deprecated"
{{input class="firstName" type="text" placeholder="first name" value=firstName }}
{{input class="lastName" type="text" placeholder="last name" value=lastName }}
<button class="submit" {{action addPerson}}>Add</button>
<br />
<table>
{{#each person in controller}}
<tr>
<td class="name">{{person.fullName}}</td>
<td><button class="delete" {{action deletePerson person}}>Delete</button></td>
</tr>
{{/each}}
</table>
How should I modify the above template to correct this?
解决方案
It looks like I just needed to give the PR a look that changed this :)
In my controller I just needed to move the addPerson / deletePerson under actions like so
App.PeopleController = Ember.ArrayController.extend({
actions: {
addPerson: function() {
var person = {
firstName: this.get('firstName'),
lastName: this.get('lastName')
};
App.Person.add(person);
},
deletePerson: function(person) {
App.Person.remove(person);
}
}
});
这篇关于直接在控制器上执行的操作处理程序已被弃用 - 以纠正这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文