1

バックボーン リレーショナルを使用していますが、次のエラーが表示されます。

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

スタックトレースが追加されました

ここに画像の説明を入力

4

1 に答える 1

0

を削除して問題を解決し、findOrCreate()次のようにモデル データを取得しました。

App.Router = Backbone.Router.extend({
  routes: {
    'note/:_id': 'show_note'
  },

  show_note: function(_id) {
    var note = new App.Models.Note({ _id: _id });
    note.fetch({
      success: function(data) {
        var mainNoteView = new App.Views.main_note({ model: note });
        $('#mainNote').append( mainNoteView.render().el );
      },
      error: function(err) {
        console.log(err);
      }
    });
  }
});
于 2013-07-02T15:58:52.960 に答える