我試圖創建一個使用ember.js和灰燼數據的應用程序,使用以下版本:錯誤在處理路由錯誤與燼數據ember.js
DEBUG: Ember : 1.7.0
DEBUG: Ember Data : 1.0.0-beta.9
DEBUG: Handlebars : 1.2.1
DEBUG: jQuery : 2.1.0
我使用RESTAdapter連接到我使用node.js編寫的api。
只要我打開我不斷收到以下錯誤應用:
Error while processing route: students undefined is not a function TypeError: undefined is not a function
at http://localhost:9000/scripts/vendor/ember-data.js:12006:34
at tryCatch (http://localhost:9000/scripts/vendor/ember.js:45818:16)
at invokeCallback (http://localhost:9000/scripts/vendor/ember.js:45830:17)
at publish (http://localhost:9000/scripts/vendor/ember.js:45801:11)
at http://localhost:9000/scripts/vendor/ember.js:29069:9
at DeferredActionQueues.invoke (http://localhost:9000/scripts/vendor/ember.js:634:18)
at Object.DeferredActionQueues.flush (http://localhost:9000/scripts/vendor/ember.js:684:15)
at Object.Backburner.end (http://localhost:9000/scripts/vendor/ember.js:147:27)
at Object.Backburner.run (http://localhost:9000/scripts/vendor/ember.js:202:20)
at apply (http://localhost:9000/scripts/vendor/ember.js:18382:27)
下面是我使用的代碼(在我粘貼它相同的順序加載):
應用。 JS
var App = window.App = Ember.Application.create({
LOG_ACTIVE_GENERATION: true,
LOG_TRANSITIONS: true,
LOG_TRANSITIONS_INTERNAL: false,
LOG_VIEW_LOOKUPS: true
});
store.js
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: 'http://localhost:3000',
serializer: DS.RESTSerializer.extend({
primaryKey: function(type) {
return '_id';
},
serializeId: function(id) {
return id.toString();
}
})
});
型號/ student.js
App.Student = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
nationality: DS.attr('string'),
createdAt: DS.attr('date')
});
路線/ app_route.js
App.StudentsRoute = Ember.Route.extend({
model: function() {
return this.store.find('student');
}
});
router.js
App.Router.map(function() {
this.resource('students', {path: '/'});
});
而下面是API的響應:
{
students: [
{
nationality: "Lorem",
lastName: "Doe",
firstName: "John",
_id: "53f87200f3750319b4791235",
createdAt: "2014-08-23T10:50:40.661Z"
},
{
nationality: "Lorem",
lastName: "Doe",
firstName: "John",
_id: "53f87299f3750319b4791234",
createdAt: "2014-08-23T10:50:40.661Z"
}
]
}
它看起來像店裏沒有加載來自API的數據,但JSON數據格式看起來不錯。任何想法可能是錯的?
謝謝!
我覺得我有完全相同的錯誤,這開始時,我沒有使用1.7.0但1.8.0 -beta.1 ...切換回1.7.0修復了我。不知道爲什麼你有這個問題,但:( – Leeft 2014-08-27 15:05:56
我相信你需要在'primaryKey'中使用一個字符串,而不是一個函數[基於文檔](http://emberjs.com/api/data/classes/DS .RESTSerializer.html#property_primaryKey)。例如'primaryKey:''。 – 2014-08-27 21:02:34