我刚刚从ember.js RC7升级到RC8,发现一个简单的模板(如下所示)会抛出一个不赞成的警告
"直接在控制器上实现的动作处理程序已弃用"
{{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>
Run Code Online (Sandbox Code Playgroud)
我应该如何修改上述模板来纠正这个问题?
Tor*_*ups 29
看起来我只需要给公关一个改变了这个:)
在我的控制器中,我只需要在这样的动作下移动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);
}
}
});
Run Code Online (Sandbox Code Playgroud)
sel*_*gsz 12
您应该actions在控制器,视图和路由中的哈希内定义您的操作以支持一致性.
请参阅https://github.com/emberjs/ember.js/pull/3091
App.ApplicationController = Em.ObjectController.extend({
actions : {
// your actions here
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3734 次 |
| 最近记录: |