正在获取和分析集合

Fetching and Parsing Collection

本文关键字:集合 获取      更新时间:2023-09-26

我已经重写了正在获取的集合的parse函数,如下所示:

parse: function(response) {
    this.total = response.total;
    return response.items;
}

此外,我已经将集合绑定到使用它的视图的渲染函数。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四次。

您可能需要将this绑定到渲染函数。更改:

this.collection.bind('reset', this.render);

收件人:

this.collection.bind('reset', this.render, this);