我有这个型号:
App.Me = DS.Model.extend({
email: DS.attr('string'),
firstname: DS.attr('string'),
lastname: DS.attr('string')
});
我试图抓取它,我的回答如下:{" email":" iamanemail@gmail.com"," firstname&# 34;:"的Mads""姓":" Mylastname"}
然后,Ember在我的控制台中说: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
所以我认为这是因为Ember期望一个名为" me"的根对象,但我该如何重写呢?
编辑:现在我的格式正确:
{"me":[{"email":"iamanemail@gmail.com","firstname":"Mads","lastname":"Mylastname"}]} main.js:33
答案 0 :(得分:2)
我使用序列化程序修复数据格式,如下所示:
App.MeSerializer = DS.RESTSerializer.extend({
primaryKey: 'email',
extractArray: function (store, primaryType, payload) {
var primaryTypeName = primaryType.typeKey;
var typeName = primaryTypeName,
type = store.modelFor(typeName);
var data = {};
var item = [];
item.push(payload)
data[typeName] = item;
console.log(JSON.stringify(data));
payload = data;
return this._super.apply(this, arguments);
}
});