0
我在我的Ember.js應用程序中收到以下錯誤。Ember.js - 加載路由時出錯:TypeError:無法設置屬性「商店」的未定義
Error while processing route: books Cannot set property 'store' of undefined TypeError: Cannot set property 'store' of undefined
at DS.Store.Ember.Object.extend.modelFor (http://localhost:8080/js/libs/ember-data.js:2986:19)
at DS.Store.Ember.Object.extend.recordForId (http://localhost:8080/js/libs/ember-data.js:2437:17)
at deserializeRecordId (http://localhost:8080/js/libs/ember-data.js:3355:23)
at deserializeRecordIds (http://localhost:8080/js/libs/ember-data.js:3369:5)
at http://localhost:8080/js/libs/ember-data.js:3335:7
at http://localhost:8080/js/libs/ember-data.js:7117:16
at http://localhost:8080/js/libs/ember.js:14899:20
at Object.OrderedSet.forEach (http://localhost:8080/js/libs/ember.js:14741:14)
at Object.Map.forEach (http://localhost:8080/js/libs/ember.js:14897:14)
at Function.DS.Model.reopenClass.eachRelationship (http://localhost:8080/js/libs/ember-data.js:7116:38)
我使用
- ember.js版本1.7.1和
- 燼,data.js版本1.0.0-beta.5。
我有以下項目:
window.App = Ember.Application.create();
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'http://localhost:8080'
});
App.Router.map(function() {
this.resource('books', { path: '/' });
});
App.BooksRoute = Ember.Route.extend({
model: function() {
return this.store.find('book');
}
});
App.Author = DS.Model.extend({
firstname: DS.attr('string'),
lastname: DS.attr('string')
});
App.Book = DS.Model.extend({
title: DS.attr('string'),
authors: DS.hasMany('author')
});
和下面是我的JSON響應http://localhost:8080/books
。
{
"books":
[
{
"id": 0,
"authors":
[
{
"id": 0,
"firstname": "Andrzej",
"lastname": "Sapkowski"
}
],
"title": "Zaklínač I: Poslední přání"
},
...
]
}
當我刪除了Author
模型和authors
關係的聲明,該應用程序工作正常。
我收到的錯誤信息沒有顯示原因,根據我在互聯網上找到的內容,我的代碼似乎沒有問題。
有什麼問題?
您可以發佈錯誤消息的完整堆棧跟蹤以及您正在使用的Ember和Ember-Data的版本嗎? – GJK 2014-10-26 18:18:27
當然可以。謝謝 – 2014-10-26 18:27:28
我將ember.js升級到1.7.1,但是我仍然遇到同樣的錯誤。 – 2014-10-26 18:33:11