我在app.js文件中定义了两个集合,如下所示:
this.shoppingCartFullPageView.collections = {
supplyCategoriesCollection: this.supplyCategoriesCollection,
orderedSuppliesCollection: this.orderedSuppliesCollection
}
以下是我的观点代码:
var ShoppingCartFullPageView = Backbone.View.extend ({
initialize: function () {
this.listenTo(this.collection, "reset", this.render);
},
render: function() {
$(this.el).html(new ShoppingCartListView ({
collection: this.collections.supplyCategoriesCollection
}).render().el);
$(this.el).append(new OrderedSupplyListView ({
collection: this.collections.orderedSuppliesCollection
}).render().el);
return this;
}
});
我有一个Backbone View,它渲染子视图,每个子视图都有自己的集合。这两个子视图正确呈现。问题出在初始化函数中。 上面的代码监听两个集合上的“重置”。我想只在其中一个集合上“listenTo”“重置”。当我尝试“this.listenTo(this.collections.supplyCategoriesCollection,”reset“,this.render);”我得到一个未定义的错误。
答案 0 :(得分:0)
修改强>
您的馆藏是否已初始化?
这个怎么样:
this.shoppingCartFullPageView.collections = {
supplyCategoriesCollection: new this.supplyCategoriesCollection(),
orderedSuppliesCollection: new this.orderedSuppliesCollection()
}