我有两个模型(用户和任务),它们是Backbone.RelationalModel
.
这两个模型的关系如下:
// Task model
var Task = Backbone.RelationalModel.extend({
relations: [
{
type: 'HasOne',
key: 'user',
relatedModel: User
}
],
urlRoot: 'someUrl'
});
然后我有一个集合,其代码如下所示:
var FollowerCollection = Backbone.Collection.extend({
initialize: function () {
_.bindAll(this);
}
model: User
});
var User = Backbone.RelationalModel.extend({
});
当我在 FollowerCollection 上进行提取时,出现以下错误:
Uncaught TypeError: Cannot read property 'idAttribute' of undefined
在主干-relation.js 的第 1565 行backbone-relation version 0.5.0
这里有一段backbone-relation.js的代码
if ( !( model instanceof Backbone.Model ) ) {
// Try to find 'model' in Backbone.store. If it already exists, set the new properties on it.
var existingModel = Backbone.Relational.store.find( this.model, model[ this.model.prototype.idAttribute ] );
这个问题与_.bindAll(this)
因为如果我评论它,它可以正常工作。
为什么?有任何想法吗?