如何更改Ember.js中的复选框后触发命名动作?任何帮助将不胜感激。
这就是我所拥有的。选中或取消选中该复选框无效。
模板:
{{input type="checkbox" on="change" action="applyFilter"}}
控制器:
actions: {
applyFilter: function() {
console.log("applyFilter");
}
}
使用观察者似乎是观察复选框更改的最简单方法
{{input type='checkbox' checked=foo}}
foo:undefined,
watchFoo: function(){
console.log('foo changed');
}.observes('foo')
http://emberjs.jsbin.com/kiyevomo/1/edit
或者,您可以创建自己的复选框的实现,以发送操作
App.CoolCheck = Ember.Checkbox.extend({
hookup: function(){
var action = this.get('action');
if(action){
this.on('change', this, this.sendHookup);
}
}.on('init'),
sendHookup: function(ev){
var action = this.get('action'),
controller = this.get('controller');
controller.send(action, this.$().prop('checked'));
},
cleanup: function(){
this.off('change', this, this.sendHookup);
}.on('willDestroyElement')
});
{{view App.CoolCheck action='cow' checked=foo}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句