2013-05-03 107 views
2

似乎我無法循環骨幹收集。我已經在幾個主題中看到了這個話題,但是這些解決方案都沒有幫助。無法循環骨幹收集

render:function() { 
     this.$el.html(this.template(this.model.attributes)); 
     var that = this; 


     console.log(this.projects.models); 
     _.each(this.projects.models, function(model) { console.log(model); }); 

     return this; 
    } 

從此我的控制檯只顯示陣列[2] 我希望看到每個模型爲好。 有誰知道我在這裏做錯了嗎?

回答

5

爲了讓您的收藏內容作爲數組,使用方法toJSON(例如:collection.toJSON()

接下來,遍歷整個集合,使用each方法的集合實例!

collection.each(function(model) { 
    console.log(model) 
}); 

如果不顯示完整的集合,那麼問題是你如何添加項目您的收藏裏,而不是在循環邏輯。

+0

然後添加更多的代碼或創建一個簡化的測試用例。 – 2013-05-03 02:05:02