Skip to content

Instantly share code, notes, and snippets.

@fnordo
Created October 10, 2012 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fnordo/3865266 to your computer and use it in GitHub Desktop.
Save fnordo/3865266 to your computer and use it in GitHub Desktop.
Example BackboneView
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