【发布时间】:2013-10-08 13:48:53
【问题描述】:
我正在编写一个主干(需要)应用程序,需要搜索一个集合以提取第一个模型(我使用的是唯一的 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 吗?
【问题讨论】:
-
可以添加LocationCollection的声明代码吗?
-
随机猜测:下划线版本
-
啊。定位:Backbone 0.9.9 和 Underscore 1.4.3
-
添加更新版本,一切正常。谢谢。