Backbone collection.findWhere问题 - 收集时出错

Ben*_*ury 1 collections backbone.js

我正在编写一个主干(带有require)应用程序,需要搜索一个集合来拉出第一个模型(我使用一个唯一的id,所以只有一个).

我遇到的问题是我收到了一个错误:

Uncaught TypeError: Object [object Object] has no method 'findWhere' 
Run Code Online (Sandbox Code Playgroud)

当它使用findWhere命令到达该行时.

视图初始化是:

initialize: function (models) {
    this.locationCollection = new LocationCollection();
    this.locationCollection.fetch();

    this.render();
},
Run Code Online (Sandbox Code Playgroud)

然后我在另一个方法中访问locationCollection,该方法的第一行是发生错误的地方:

createCrate: function (eventname) {
    var setLocationList = this.locationCollection.findWhere({ Name: $('#location').val() });
    console.log($('#location').val());
    console.log(setLocationList);        
},
Run Code Online (Sandbox Code Playgroud)

这是LocationCollection的声明代码:

define([
  'jquery',
  'underscore',
  'backbone',
  'model/LocationModel'
], function ($, _, Backbone, LocationModel) {

   var LocationCollection = Backbone.Collection.extend({
      model: LocationModel,
      url: "/api/locations"
   });

   return LocationCollection;

});
Run Code Online (Sandbox Code Playgroud)

我可以访问视图中其他位置的this.localCollection中的项目,并将它们输出到主干类型扩展中,因此已经填充了该集合.

知道为什么这个系列不能调用findWhere吗?

nik*_*shr 5

确保你有足够的版本,你的错误应该消失.