バックボーン リレーショナルを使用していますが、次のエラーが表示されます。
Uncaught TypeError: Cannot read property 'idAttribute' of undefined
show_note
ルートにアクセスすると。
App.Router = Backbone.Router.extend({
routes: {
'note/:_id': 'show_note'
},
show_note: function(_id) {
console.log('this is the show_note route for _id: ' + _id);
var note = new App.Models.Note.findOrCreate({ _id: _id });
var note_view = new App.Views.main_note({ model: note });
note.fetch();
}
});
console.log は「_id」を受け取ります。しかし、インスタンス化しようとするとvar note
、エラーが発生します。これを修正するにはどうすればよいですか?
編集1
Note モデルの追加:
App.Models.Note = Backbone.RelationalModel.extend({
urlRoot: '/notes',
idAttribute: '_id',
relations: [{
type: Backbone.HasMany,
key: 'tags',
relatedModel: 'App.Models.Tag',
reverseRelation: {
key: 'note',
includeInJSON: '_id'
}
}]
});
編集2
スタックトレースが追加されました