我正在使用带骨干的布局管理器,但无法从集合中获取模型。下面是代码。即使元素存在,我也无法从 this.collection.models 中获取元素,它的显示为空。
集合快照
//Models
App.Models.StoreModel = Backbone.Model.extend({});
//Featured Products Collections
App.Collections.StoreFeaturedProducts = Backbone.Collection.extend({
model : App.Models.StoreModel,
url:"../JSON/products.json",
parse : function(response){
return response.products;
}
});
//In Router
this.featureList = new App.Collections.StoreFeaturedProducts(); /* initialize featureList */
this.featureView = new App.Views.DisplayView2({collection : this.featureList}); /* create featureSlider View object */
App.Layouts.AppLayout.insertViews({ /* insert view to layout */
"wrapper2" : this.featureView
});
this.featureList.fetch(); /* fetch json */
//Render Layout
App.Layouts.AppLayout.render();
//View![enter image description here][2]
App.Views.DisplayView2 = Backbone.View.extend({
template : '#view1',
initialize : function(options) {
this.collection.bind('reset', this.render, this);
//this.model.bind('reset', this.render, this);
},
beforeRender : function() {
console.log(this.collection) - shows the elements
this.collection.each(function(m) {
//does not go through
}, this);
}
serialize : function() {}
});