Created
May 15, 2012 04:41
-
-
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.
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
// 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