Skip to content

Instantly share code, notes, and snippets.

@imehr
Created February 15, 2012 12:39
Show Gist options
  • Save imehr/1835413 to your computer and use it in GitHub Desktop.
Save imehr/1835413 to your computer and use it in GitHub Desktop.
BackboneJS View
// render() function is a no-op (an empty function).
// Your view should call this function whenever the view needs to be redrawn.
var UserView = Backbone.View.extend(
initialize: function(){
/* ... */
}
render: function(){
/* ... */
}
);
var TodoView = Backbone.View.extend({
template: _.template($("#todo-template").html()),
render:function(){
$(this.el).html(this. template(this.model.toJSON()));
return this;
}
});
@imehr
Copy link
Author

imehr commented Feb 15, 2012

this.model points to a model’s instance and is passed through to the view upon instantiation.
The model's toJSON() function essentially returns the model's raw attributes, ready for the template to use.
new Todo View({model: new Tool});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment