Skip to content

Instantly share code, notes, and snippets.

@talentedmrjones
Created October 6, 2013 21:24
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 talentedmrjones/6859278 to your computer and use it in GitHub Desktop.
Save talentedmrjones/6859278 to your computer and use it in GitHub Desktop.
BackboneJs Event Re-Delegation
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