Created
June 26, 2013 17:08
-
-
Save matsukaz/5869302 to your computer and use it in GitHub Desktop.
Viewに登録したイベントが複数回呼ばれてしまう場合の対処 ref: http://qiita.com/matsukaz/items/8145f362a601176ae88f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.off(); | |
this.undelegateEvents(); | |
this.remove(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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