次のようなバックボーン コレクションがあります。
var FooCollection = Backbone.Collection.extend({
model:Foo,
initialize: function (attributes, options) {
this.barId = options.barId;
}
});
var Foo = Backbone.Model.extend({});
これを初期化しようとすると、 の_prepareModel()
関数で「Uncaught TypeError: undefined is not a function」が発生します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
誰が私が間違っているのか教えてもらえますか?