使用Ember.js复选框输入帮助器来触发更改事件的操作? [英] Trigger an action on the change event with Ember.js checkbox input helper?
本文介绍了使用Ember.js复选框输入帮助器来触发更改事件的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在更改Ember.js中的复选框时触发命名动作?任何帮助将不胜感激。
How can I fire a named action upon changing a checkbox in Ember.js? Any help will be greatly appreciated.
这是我所拥有的。检查或取消选中该复选框不起作用。
Here is what I have. Checking or unchecking the checkbox has no effect.
模板:
{{input type="checkbox" on="change" action="applyFilter"}}
控制器:
Controller:
actions: {
applyFilter: function() {
console.log("applyFilter");
}
}
推荐答案
观察者似乎是最简单的方式来观看复选框
using an observer seems like the easiest way to watch a checkbox changing
{{input type='checkbox' checked=foo}}
代码
Code
foo:undefined,
watchFoo: function(){
console.log('foo changed');
}.observes('foo')
示例
http://emberjs.jsbin.com/kiyevomo/1/edit
或者您可以创建自己的实现复选框发送操作
Or you could create your own implementation of the checkbox that sends an action
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')
});
自定义视图
Custom View
{{view App.CoolCheck action='cow' checked=foo}}
示例
http://emberjs.jsbin.com/kiyevomo/ 6 /编辑
这篇关于使用Ember.js复选框输入帮助器来触发更改事件的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文