在下面的代码中,我的click事件代表和所有三个'click'我的视图层次结构中的处理程序被解雇。
不过我也想火'edit'在我的整个视图层次结构中。'edit'只是我的元素的目标'child' view.
Template
<script type="text/x-handlebars">
{{#view App.GrandparentView}}
{{#view App.ParentView}}
{{#view App.ChildView}}
<span {{action "edit" target="view"}}>Click Me</span>
{{/view}}
{{/view}}
{{/view}}
</script>
JavaScript
App.GrandparentView = Ember.View.extend({
click: function() {
console.log('Grandparent Click Fired!');
},
edit: function () {
console.log('GrandParent edit fired');
}
});
App.ParentView = Ember.View.extend({
click: function() {
console.log('Parent Click Fired!');
},
edit: function () {
console.log('Parent edit fired');
}
});
App.ChildView = Ember.View.extend({
click: function() {
console.log('Child Click Fired!');
},
edit: function () {
console.log('Child edit fired');
}
});
是否无法在视图层次结构中委托目标处理程序?我什么dont想要做的是这样的:
App.ChildView = Ember.View.extend({
click: function() {
console.log('Child Click Fired!');
},
edit: function () {
console.log('Child edit fired');
this.get('parentView').edit(); //DO NOT WANT TO DO THIS.
}
});
这里有一个jsFiddle http://jsfiddle.net/lifeinafolder/xN2my/作为例子进行测试。
这看起来与您大约一周前发布的问题相同。据我所知,ember 中没有实现这样的功能。事件被传播到视图层次结构,但操作名称丢失,并且默认click
处理程序被触发。
我发现的唯一解决方法是重新打开 Ember.View 类本身,并重写单击处理程序,如下所示:
Ember.View.reopen({
click: function(event){
if(event.view !== this && this[event.actionName]){
return this[event.actionName](event);
}
}
})
请参阅这里的小提琴:
http://jsfiddle.net/Sly7/zZyCS/ http://jsfiddle.net/Sly7/zZyCS/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)