在以下代码中:
var AppView = Backbone.View.extend({
events:{
"click .button":"cancel"
},
cancel:function() {
console.log("do something...");
},
onSomeEvent: function() {
this.$el.undelegate('.button', 'click', this.cancel);
}
});
var view = new AppView();
我需要从具有“this.cancel
”类的元素中取消button
处理程序。不幸的是,onSomeEvent方法中的this.$el.undelegate
不起作用。
如何删除该事件处理程序?
答案 0 :(得分:3)
尝试类似:
....
onSomeEvent: function() {
this.delegateEvents(
_(this.events).omit('click .button')
);
}
<强>更新强>
你的意思是:this.events[event] = "someEvent";
//call delegateEvents() on the view to re-bind events
this.delegateEvents();