我有一個對象「居住」和住宅有很多細節。當從服務器返回數據時,如何使用序列化程序「extractSingle」來映射其關係?我有以下,我得到錯誤「無法獲取屬性'toString的未定義或空引用」。有人能告訴我我在這裏做錯了嗎?燼數據提取單個串行器
App.Residence = DS.Model.extend({
residence_ID: attr('number'),
house_Number: attr('string'),
street: attr('string'),
city_ID: attr('number'),
state_ID: attr('number'),
zip: attr('string'),
apt: attr('string'),
client_ID: attr('number'),
client: null,
lead: null,
projectDetails: DS.hasMany('projectDetail')
});
App.ResidenceSerializer = DS.WebAPISerializer.extend({
primaryKey: 'residence_ID',
extractSingle: function (store, primaryType, payload) {
var primaryTypeName = primaryType.typeKey;
var typeName = primaryTypeName,
type = store.modelFor(typeName);
var data = {};
data[typeName] = payload;
data.projectDetails = [];
var normalizedArray = payload.projectDetails.map(function (nav) {
data.projectDetails.push(nav);
}, this);
payload.projectDetails = payload.projectDetails.mapProperty('projectDetailID');
payload = data;
return this._super.apply(this, arguments);
},
normalizeHash: {
projectDetails: function (hash) {
hash.residence_ID = hash.id;
hash.id = hash.projectDetailID;
return hash;
},
residence: function (hash) {
hash.residence_ID = hash.id;
return hash;
}
}
});
這裏是JSON從服務器返回
{
"residence_ID":3532,
"house_Number":"243",
"street":"Main St.",
"city_ID":2,
"state_ID":33,
"zip":"11111",
"apt":"35",
"client_ID":3598,
"projectDetails":[{"projectDetailID":4947,"residence_ID":3532"}, {"projectDetailID":4947,"residence_ID":3532}]
}
你能告訴你的JSON是如何下來沒有更新? – Kingpin2k
我剛發佈了json。不知道爲什麼我不能把它放在代碼部分 –