在我的应用程序中,我有如下所示的 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/