Jon*_*hon 8 collections backbone.js
我有一个从集合中呈现自己的视图:
render: function() {
$(this.el).html(JST['templates/menu']({collection: this.collection }));
$('#nav').html(this.el);
}
Run Code Online (Sandbox Code Playgroud)
在视图初始化程序中,我在视图的渲染函数上绑定集合的add事件:
initialize: function() {
this.render();
var self = this;
this.collection.bind("add", function(event){
self.render();
});
}
Run Code Online (Sandbox Code Playgroud)
在应用程序的其他地方,我将一个项目添加到集合中.
bookSubscription_collection.add(model);
Run Code Online (Sandbox Code Playgroud)
该代码的问题是,如果我向集合中添加新项,则会重新呈现集合中的所有项.
有没有办法在不重新渲染所有其他项目的情况下将新项目添加到集合中,只是渲染新项目?
| 归档时间: |
|
| 查看次数: |
3073 次 |
| 最近记录: |