是否可以在子视图中覆盖closeClick
功能?单击.close
时,只运行子级closeClick
函数而不是父级。
var ParentView = Backbone.View.extend({
events:{
"click .close": "closeClick"
},
closeClick: function(){
//do parent stuff
}
});
var ChildView = ParentView.extendable.extend({
events:{
"click .close": "closeClick",
//more child events
},
closeClick: function(){
//only do child stuff not parent when .close is clicked
}
});
答案 0 :(得分:1)
您所写的内容可以正常使用正常的Backbone .extend
。不知道这个奇怪的extendable
陈述是什么 - 这可能是打破它的原因。
var ParentView = Backbone.View.extend({
events: {
"click .close": "closeClick"
},
closeClick: function(){
//do parent stuff
}
});
var ChildView = ParentView.extend({
events: function() {
var parentEvents = _.result(ParentView.prototype, 'events');
return _.extend({
'keyup input': 'someOtherChildEvent'
}, parentEvents);
},
closeClick: function() {
//only do child stuff not parent when .close is clicked
}
});