2013-05-03 82 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