Created
December 13, 2011 15:36
-
-
Save 4bu/1472559 to your computer and use it in GitHub Desktop.
This file contains 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
var PersonModel = Backbone.Model.extend(); | |
var PersonView = Backbone.View.extend({ | |
initialize: function () { | |
_.bind(this, 'render’); | |
this.model.bind(‘change:name’, this.render); | |
}, | |
render: function () { | |
$(‘body’).html(this.model.get(‘name’)); | |
} | |
}); | |
var personModel = new PersonModel(); | |
personModel.set({name: ‘Marco Francke’}); | |
var personView = new PersonView({ | |
model: personModel | |
}); | |
// initial render the name | |
personView.render(); | |
// new name | |
personModel.set({name: ’BackboneJS’}); | |
// another new name | |
personModel.set({name: ’Backbone rocks’}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I suggest updating this to my forked version, which fixes smart quotes issue, and also changes view binding to something that works (see http://stackoverflow.com/questions/7087564/what-is-the-difference-between-these-backbone-underscore-bind-methods ).
Oh and I added a delay to second name change so that both can be seen.