2013-04-07 4 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

ответ

0

Если вы действительно видите элементы на линии, где ваш писал:

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

этот конкретный массив должен быть доступ через models собственность В сборниках:

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

Надеюсь, это поможет.

Смежные вопросы