发现render方法从来不执行,百思不得骑姐,最后发现这东西需要手动绑定一个model
再给model绑定事件,原来是手动档的…… :arrow: :lol:
[url]http://stackoverflow.com/questions/8972294/backbone-js-nothing-renders-except-when-manually[/url]
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().
再给model绑定事件,原来是手动档的…… :arrow: :lol:
[url]http://stackoverflow.com/questions/8972294/backbone-js-nothing-renders-except-when-manually[/url]
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().
本文介绍了一个关于Backbone.js框架中视图渲染的问题。通常情况下,当模型发生变化时,与之绑定的视图会自动调用render方法进行重新渲染。然而,在某些情况下需要手动绑定模型并设置事件监听来触发渲染过程。
489

被折叠的 条评论
为什么被折叠?



