【发布时间】:2014-04-17 07:12:48
【问题描述】:
我对集合中的模型进行了循环,以使用集合描述中的函数 fetchAll 获取。
fetchAll: function(){
this.counter=0;
self = this;
for (var i=0;i<this.models.length; i++){
this.models[i].fetch({
success: function(){
self.counter +=1;
if (self.counter == self.models.length){
alert('done');
self.doneFetchAll = true;
}
}
});
//console.log(i);
}
获取完成后,我看到一个警报,并且集合属性doneFetchAll 设置为true....但是完成后如何触发视图的渲染?
1) 主干中是否有可能监听集合的特定属性的变化,如果是肯定的,再次调用渲染?
或
2) 有没有更好的方法来获取集合中的所有模型,然后重新渲染视图?
所有这些监听变化的努力都失败了(whiting the initialize: function() of the view):
this.listenTo(this.collection, "change:doneFetchAll", this.render);
或
this.collection.on("change:doneFetchAll", this.render, this);
谢谢。
【问题讨论】: