我正在使用 Backbone-Relational,我收到以下错误:
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
添加了堆栈跟踪