Created
October 6, 2013 21:24
-
-
Save talentedmrjones/6859278 to your computer and use it in GitHub Desktop.
BackboneJs Event Re-Delegation
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
Backbone.View.extend({ | |
tagName:'div', | |
id:'cart', | |
// this.$el is created and events are initially delegated to it during view instantiation | |
events:{ | |
"click .checkout":"onClick" | |
} | |
renderCount:0, | |
render: function () { | |
this.$el.html(...).appendTo('body'); | |
if (this.loadCount) { | |
this.delegateEvents(); // RE-delegate events on subsequent renders | |
} | |
this.loadCount++; | |
}, | |
remove: function () { | |
this.$el.remove(); // .remove also removes delegated events! | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment