Skip to content

Instantly share code, notes, and snippets.

@matsukaz
Created June 26, 2013 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsukaz/5869302 to your computer and use it in GitHub Desktop.
Save matsukaz/5869302 to your computer and use it in GitHub Desktop.
Viewに登録したイベントが複数回呼ばれてしまう場合の対処 ref: http://qiita.com/matsukaz/items/8145f362a601176ae88f
var AView = Backbone.View.extend({
el: $("#main"),
events: {
"click button#btn1": "onBtn1Click"
}
...
});
var BView = Backbone.View.extend({
el: $("#main"),
events: {
"click button#btn1": "onBtn1Click"
}
...
});
this.off();
this.undelegateEvents();
this.remove();
// Clears all callbacks previously bound to the view with `delegateEvents`.
// You usually don't need to use this, but may wish to if you have multiple
// Backbone views attached to the same DOM element.
undelegateEvents: function() {
this.$el.off('.delegateEvents' + this.cid);
return this;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment