我有一个 Backbone 集合,如下所示:
var FooCollection = Backbone.Collection.extend({
model:Foo,
initialize: function (attributes, options) {
this.barId = options.barId;
}
});
var Foo = Backbone.Model.extend({});
当我尝试初始化它时,我_prepareModel()
在Backbone.Collection
.
坏电话在model = new this.model(attrs, options)
.
// Prepare a model or hash of attributes to be added to this collection.
_prepareModel: function(model, options) {
options || (options = {});
if (!(model instanceof Model)) {
var attrs = model;
options.collection = this;
model = new this.model(attrs, options); // <-- BLOWS UP HERE
if (!model._validate(model.attributes, options)) model = false;
} else if (!model.collection) {
model.collection = this;
}
return model;
},
当我在调试器中单步执行时,此时_prepareModel()
的类型看起来是,实际上是未定义的。this
child
this.model
谁能告诉我我做错了什么?