Ember模型有很多不起作用

时间:2015-09-18 20:29:38

标签: ember.js

我遇到了一些非常简单的Ember设置问题。我有两个单独的模型appointmentitem。我的appointment模型有一个属性appointmentBinshasMany('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: ""
  // ...
}

我不知道我错过了什么 - 这似乎并不是特别复杂,但我只是无法在约会模型中解析返回的数组。非常感谢!

1 个答案:

答案 0 :(得分:1)

它是deserialize,而不是deserializer http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html