Skip to content

Instantly share code, notes, and snippets.

@Breefield
Created August 10, 2012 20:43
Show Gist options
  • Save Breefield/3317693 to your computer and use it in GitHub Desktop.
Save Breefield/3317693 to your computer and use it in GitHub Desktop.
Backbone.js Template Binding
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