我有一个Backbone集合,如下所示:
var FooCollection = Backbone.Collection.extend({ model:Foo,initialize: function (attributes,options) { this.barId = options.barId; } }); var Foo = Backbone.Model.extend({});
当我尝试初始化这个,我得到Backbone.Collection的_prepareModel()函数中的“未捕获TypeError:undefined不是一个函数”.
不好的电话是在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()时,它看起来像这个时候的类型是child,而this.model实际上是未定义的.
有谁能告诉我我做错了什么?