0
我一直在周末学习Backbone.js,在构建一个简单的应用程序时,出现了一个我不太明白的问题。Backbone.js集合将其自身副本添加到实例化集合上?
我有一个视图创建一个集合并呈现集合的视图。即:
gallery: function(page,id) {
var that = this;
this.galleryCollection = new GalleryCollection;
this.galleryCollection.setID = id;
this.galleryCollection.region = page;
this.galleryCollection.fetch({add: true,
success: function(model,response) {
//render logic here
});
}
这个按预期工作;调用console.log(this.model.models)仅显示与上述集合关联的模型的集合。
然而,构建了这样的代码:
gallery: function(page,id) {
this.galleryCollection = new GalleryCollection({setID: id, region: page})
this.galleryCollection.fetch()
//additional code...
增加了新的实例化集合模型被获取的集合。我可能在这里错过了一些基本的Backbone.js范例,但为什么集合本身会被添加到集合中呢?
没错,使用新的GalleryCollection([],{setID:id,region:page})' – Yaroslav
在文档中也有相当清楚的解释,我需要仔细阅读这些内容!谢谢 – primer