在骨干网收集着循环 [英] Cant loop over backbone collection
问题描述
看来,我不能通过骨干收集循环,我见过这个话题在多个线程,但没有这些解决方案的帮助。
It seems that I cant loop through a backbone collection, Ive seen this topic in several threads, but none of those solutions help.
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]
我希望看到每个模型为好。
有谁知道我在做什么错在这里?
from this my console only shows Array[2] I would expect to see each model as well. Does anyone know what I'm doing wrong here ?
推荐答案
要得到你的收藏内容为一个数组,使用的方法的toJSON
(例如: collection.toJSON()
)
To get your collection content as an array, use the method toJSON
(e.g.: collection.toJSON()
)
接下来,遍历整个集合,使用关于收集每个实例
方法!
Next, to loop over your entire collection, use the each
method on the collection instances!
collection.each(function( model ) {
console.log(model)
});
如果这个不显示完整的集合,然后,问题是你如何添加项目您的收藏里,而不是在循环逻辑。
If this don't show your full collection, then the problem is in how you add items inside your collection, not in the looping logic.
这篇关于在骨干网收集着循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!