javascript - 在主干中搜索集合

标签 javascript backbone.js backbone.js-collections

在我的应用程序中,我有如下所示的 Backbone 集合:

App.Collections.SurveyReportSets = Backbone.Collection.extend({
  url: '/survey_report_sets',
  model: App.Models.SurveyReportSet,

  byReportType: function(report_type) {
    return this.where({report_type: report_type});
  },

  byReportOrganizationType: function(report_organization_type) {
    return this.where({report_organization_type: report_organization_type});
  }
});

当我只使用其中之一时,此搜索效果非常好。但是当我尝试同时使用它们时,它们不起作用。以下是我的使用方法:

var my_collection = this.collection.byReportType(this.model.get('report_type')).byReportOrganizationType(this.model.get('report_organization_type'))

Backbone 返回以下错误:

TypeError: this.collection.byReportType(...).byReportOrganizationType is not a function

我做错了什么?

最佳答案

可能byReportOrganizationType失败,因为byReportType返回满足条件(报告类型)的模型,但它不返回Backbone.Collection,而是模型数组。该数组显然没有定义 byReportOrganizationType 函数

关于javascript - 在主干中搜索集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34942798/

相关文章:

javascript - Backbone.js 集合比较器按多个字段排序?

javascript - 如何从 JSON 填充 Backbone 集合

javascript - 如何正确使用jsPDF库

javascript - Jquery代码在点击时没有改变

javascript - 图表未使用 D3 中的转换更新新数据

javascript - 主干模板方法差异

javascript - 在递增/递减时将整数限制为数组 indeces

javascript - Backbone.js 模型事件未触发

javascript - Backbone.js 从集合中删除模型

javascript - 为什么使用定义的函数无法获取Backbone集合模型?