Skip to content

Instantly share code, notes, and snippets.

@joneath
Created May 15, 2012 04:41
Show Gist options
  • Save joneath/2699186 to your computer and use it in GitHub Desktop.
Save joneath/2699186 to your computer and use it in GitHub Desktop.
Helper method for Backbone.js views to add data bindings to DOM events. It's still up to the user to add data-cid attributes to bound DOM nodes.
// View Usage
// events: {
// "click .message": withModel("messageOverlay")
// },
function withModel(callback) {
return function(e) {
var model = this.collection.getByCid($(e.currentTarget).attr("data-cid"));
this[callback](model, e);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment