Created
October 10, 2012 12:22
-
-
Save fnordo/3865266 to your computer and use it in GitHub Desktop.
Example BackboneView
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
PageView = Backbone.View.extend({ | |
initialize: function(){ | |
// If model has changed, update view accordingly: | |
this.model.bind("change", this.render, this); | |
}, | |
render: function(evt){console.warn('called: view::render'); | |
/* | |
* Normally we maybe would/could do something like this, but | |
* how can we update the View if we have initialized it with | |
* an already rendered markup instead of a template? | |
*/ | |
$(this.el).html(_.template(this.model.toJSON())); | |
return this; | |
}, | |
events: { | |
"click .update-page-title": "updatePageTitle" | |
}, | |
updatePageTitle: function ( event ){ | |
this.model.set({ | |
title: 'FooTitle' | |
}); | |
this.model.save(); | |
return false; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment