Javascript 获取和解析集合
我已经重写了正在获取的集合的解析函数,如下所示:Javascript 获取和解析集合,javascript,backbone.js,Javascript,Backbone.js,我已经重写了正在获取的集合的解析函数,如下所示: parse: function(response) { this.total = response.total; return response.items; } 此外,我还将集合绑定到使用它的视图的render函数。 this.collection.bind'reset',this.render 在集合的初始化函数中获取集合本身: this.collection.fetch{data:params} 然后在子视图中访问集合:
parse: function(response) {
this.total = response.total;
return response.items;
}
此外,我还将集合绑定到使用它的视图的render函数。
this.collection.bind'reset',this.render
在集合的初始化函数中获取集合本身:
this.collection.fetch{data:params}
然后在子视图中访问集合:
render: function() {
var catalog, pages;
catalog = new App.Views.Catalog({collection: this.collection});
pages = new App.Views.Pages({collection: this.collection});
return this;
}
注:
我能让它工作的唯一方法是将绑定更改为:this.collection.bind'add',this.render;,最后调用render四次。您可能需要将其绑定到render函数。更改:
this.collection.bind('reset', this.render);
致:
我目前的答案可能无法解决这个问题。你能在哪里获取对象,在哪里查看这个.total的值吗?我应该提到我有:uu.bindAllthis,'render',this.collection.bind'reset',this.renderOK cool。您是否介意发布更多代码,尤其是在调用fetch的地方,以及在哪里可以看到total未设置的问题?
this.collection.bind('reset', this.render, this);