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

时间:2013-10-08 13:48:54

标签: backbone.js collections

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

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

Uncaught TypeError: Object [object Object] has no method 'findWhere' 

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

视图初始化为:

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

    this.render();
},

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

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

这是LocationCollection的声明代码:

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

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

   return LocationCollection;

});

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

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

1 个答案:

答案 0 :(得分:5)

确保您拥有足够的版本,并且您的错误应该消失。

相关问题