如何使用RESTAdapter和Ember Data 1.0.0 beta 3延迟加载子对象

时间:2013-11-17 23:03:28

标签: ember.js ember-data

我在网上找到的例子显示如下:

Flashcards.Subject = DS.Model.extend({
  name: DS.attr('string'),

  flashGroups: DS.hasMany('flashGroup', {async: true})
});

Flashcards.FlashGroup = DS.Model.extend({
  name: DS.attr('string'),

  subject: DS.belongsTo('subject')
});

然后按如下方式格式化JSON:

{"subject": {"id": 1, "name": "foo", "links": {"flash_groups": "/subjects/1/flash_groups"}}}

当我尝试sumSubject.get('flashGroups')时,没有任何反应。

1 个答案:

答案 0 :(得分:0)

我相信有一个错误,links键没有被贬低。尝试返回以下JSON:

{"subject": {"id": 1, "name": "foo", "links": {"flashGroups": "/subjects/1/flash_groups"}}}

(使用flashGroups代替flash_groups