Created
February 15, 2012 12:39
-
-
Save imehr/1835413 to your computer and use it in GitHub Desktop.
BackboneJS View
This file contains hidden or 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
// 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; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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});