以下のバックボーン モデルには、ネストされたバックボーン コレクションがあります。
var Student = Backbone.Model.extend({
firstName: null,
lastName: null,
initialize: function() {
this.programCollection = new ProgramCollection({});
}
});
var ProgramCollection = Backbone.Collection.extend({
model: Program
});
ただし、Programオブジェクトをコレクションに追加しようとすると...
var testStudent = new Student();
testStudent.get("programCollection").add(new Program());
次のエラーが表示されます。
プロパティ 'add' の値を取得できません: オブジェクトが null または未定義です
programCollection が定義されていないため、明らかに間違った方法でやっています。