在下面的代碼:如何從視圖中刪除事件一處理程序?
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();
我需要從與 'button
' 類元素undelegate this.cancel
處理程序。不幸的是,onSomeEvent方法中的this.$el.undelegate
不起作用。
我該如何刪除該事件處理程序?
嘗試'這個$ el.off( '點擊',」 .button ',thiscancel); ' –
不幸的是,它不起作用:( – Erik