backbone.js的render方法

发现render方法从来不执行,百思不得骑姐,最后发现这东西需要手动绑定一个model
再给model绑定事件,原来是手动档的……  


http://stackoverflow.com/questions/8972294/backbone-js-nothing-renders-except-when-manually


Kevin Peel:

In most Backbone examples, render() is implicitly called because a model is set on a view, and that model is tied to the view's render() function.

More specifically, when initializing a view you'd normally have a call where you bind your view's render() function to a model being set/changed, like this:

initialize: function() {
    this.model.bind('change', this.render, this);
    // ... your init stuff here ...
}
Whenever the model is changed, a change event is fired which triggers your view and calls render().

你可能感兴趣的:(JavaScript,Ajax)