我遇到了一些非常简单的Ember设置问题。我有两个单独的模型appointment
和item
。我的appointment
模型有一个属性appointmentBins
,hasMany('item')
。但是,阵列总是空着,我不知道为什么。以下是相关模型:
// appointment model
let attr = DS.attr;
export default DS.Model.extend({
// ...
appointmentBins: DS.hasMany('item'),
confirmed: attr('boolean'),
specialInstructions: attr('string'),
// ...
});
// item model
let attr = DS.attr;
export default DS.Model.extend({
title: attr('string'),
userComments: attr('string'),
internalComments: attr('string'),
// ...
});
以下是我使用的appointment
序列化程序:
export default DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
isNewSerializerAPI: true,
attrs: {
appointmentBins: { serialize: 'ids', deserializer: 'records'},
// ...
}
});
最后,这是来自网络电话的响应:
appointment: {
appointment_bins: [,…]
0: {id: 27, title: "", user_comments: null, internal_comments: null, user_id: 23, item_category_id: 10,…}
1: {id: 28, title: "", user_comments: null, internal_comments: null, user_id: 23, item_category_id: 10,…}
2: {id: 29, title: "", user_comments: null, internal_comments: null, user_id: 23, item_category_id: 10,…}
3: {id: 30, title: "", user_comments: null, internal_comments: null, user_id: 23, item_category_id: 10,…}
confirmed: false
id: "f2eb7da8b2b31f2ebad0"
special_instructions: ""
// ...
}
我不知道我错过了什么 - 这似乎并不是特别复杂,但我只是无法在约会模型中解析返回的数组。非常感谢!
答案 0 :(得分:1)
它是deserialize
,而不是deserializer
http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html