Created
August 10, 2012 20:43
-
-
Save Breefield/3317693 to your computer and use it in GitHub Desktop.
Backbone.js Template Binding
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 TodoView = Backbone.View.extend({ | |
tagName: 'li', | |
template: _.template($('#item-template').html()), | |
// Ensure our view knows about the association to it's model | |
initialize: function() { | |
this.model.bind('change', this.render, this); | |
}, | |
// Drop that model into the template and have the template re-render | |
render: function() { | |
this.$el.html(this.template(this.model.toJSON())); | |
return this; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment