According to Backbone.js documentation:
Whenever a user interface action causes a change in a model attribute, the model fires a βchangeβ event; all Views displaying model data are reported on the event, forcing them to re-display.
So, I believe that the render () method should be attached to the "change" event by default. However, the following code does not work:
TestModel = Backbone.Model.extend({}); TestView = Backbone.View.extend({ render: function() { alert('render called'); } }); var mod = new TestModel; var view = new TestView({model:mod}); mod.change();
It only works if I add an explicit bind call:
initialize: function() { this.model.bind('change', this.render, this); }
Does this mean that my understanding of the render () callback is wrong by default, and we should always bind the render () callback manually?
source share