如何将一组模型合并为一个并重新生成结果?
我有以下内容:
var View1 = Backbone.View.extend({
tagName : 'li',
template: 'items',
initialize: function(){
this.listenTo(this.model, 'sync', this.render);
},
serialize: function() {
return this.model.toJSON();
}
});
View2 = Backbone.View.extend({
tagName : 'ol',
initialize: function() {
this.collection.on('sync', _.bind(this.render, this));
},
beforeRender: function() {
var self = this;
this.collection.each(function(item) {
self.insertView(new View1({model: item}))
})
}
});
myCollection = Backbone.Collection.extend({
url: function() {
return 'path to json file here'
},
parse: function(response){
return response.data;
}
});
我特别提到
this.collection.each(function(item) {
self.insertView(new View1({model: item}))
})
到目前为止它有效,但是当我有100个项目的结果时,它会创建100个视图,我想避免这种情况,那么我该如何实现呢?