2013-11-27 65 views
0

好像每Q &一对同样的问题有不同的原因,为什么它不工作。我在渲染中有这个简单的迭代器...不能重复骨干收集...再次

render: function() { 
     console.log('MembersView render collection',this.collection); 
     //_.each(this.collection.models, function (model){ 
     this.collection.each(function (model) { 
      console.log('MembersView render model',model); 
     }); 
     this.$el.html(template({ "members":this.collection })); 
     return this.el; 
    }, 

这里是Chrome控制台,显示this.collection中的内容。你可以清楚地看到它是一个集合......

enter image description here

然而,我不能重复。控制台应该记录7个成员模型,而不是。我不知道发生了什么。我使用this.collection.on('reset'...调用在正确的时间渲染。你能看到我做错了吗?我真的非常感谢你的帮助。

感谢您的期待。

+3

而不是使用'console.log'的,使用'debugger'。控制台日志实际上写了一个奇怪的参考,它可以*改变*。意思是,当你的代码执行,但后来稀少,在这种情况下,控制台将更新以反映人口集合的集合可能是空的。 – meagar

+0

哇。好的,我会试试这个。 – Locohost

+0

令人难以置信。我从调用render复位事件切换,使用获取成功回调,它工作正常。那么我现在是否知道BB重置事件会在正在填充的集合之前触发* before *发布这个答案,我会接受它。谢谢!!!!!!!!! – Locohost

回答

0

有一个在集合属性models,你可以使用:

for(var i=0; i<this.collection.length; ++i){ 
    console.log('MembersView render model',this.collection.models[i]); 
}