1
我有這樣的模式:灰燼數據需要一個根元素
App.Me = DS.Model.extend({
email: DS.attr('string'),
firstname: DS.attr('string'),
lastname: DS.attr('string')
});
和我想要獲取它,我的回答是這樣的:{「電子郵件」:「[email protected]」 「名字」:「的Mads」,「姓氏」:「Mylastname」}
灰燼接着說THW按照我的控制檯:
WARNING: Encountered "email" in payload, but no model was found for model name "email" (resolved model name using DS.RESTSerializer.typeForRoot("email")) ember-1.8.0.js:15358
WARNING: Encountered "firstname" in payload, but no model was found for model name "firstname" (resolved model name using DS.RESTSerializer.typeForRoot("firstname")) ember-1.8.0.js:15358
WARNING: Encountered "lastname" in payload, but no model was found for model name "lastname" (resolved model name using DS.RESTSerializer.typeForRoot("lastname")) ember-1.8.0.js:15358
Error: Assertion Failed: The response from a findAll must be an Array, not undefined
所以我認爲這是因爲灰燼預計稱爲根對象「我「,但我該如何重寫它?
編輯:現在,我得到了正確的格式:
{"me":[{"email":"[email protected]","firstname":"Mads","lastname":"Mylastname"}]} main.js:33
能否請您解釋一下我爲什麼這個錯誤發生以及如何修復已完成? – 2015-05-22 12:08:38
它發生,因爲Ember希望數據遵循一定的約定,因此預期JSON有一個根元素。如果該解決方案沒有根元素,該解決方案將重寫JSON。 – 2015-05-22 12:34:12
這似乎不工作了:/ – 2016-04-21 02:35:50