2013-04-07 58 views
0

我正在使用佈局管理器與骨幹網,我無法從集合中獲取模型。 以下是代碼。即使元素存在,我也無法從this.collection.models獲取元素。無法循環通過骨幹網收集

收集snopshot enter image description here

//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() {} 


}); 
+1

你可以請張貼實際代碼的相同部分?我們這裏有一個不會跑一個,除了它和快照之間有差異。 – snedkov 2013-04-07 16:38:20

回答

0

如果你真的看到被你寫的行中的元素:

console.log(this.collection) - shows the elements 

特定陣列應該通過集合models屬性來訪問:

_.each(this.collection.models, function(m) { 
    // ... 
}); 

希望這會有所幫助。