Ember data rendering hasMany

ぃ、小莉子 提交于 2019-12-23 20:16:36

问题


In my ember app I have a models:

App.Schedule = DS.Model.extend({
    manager:DS.belongsTo('App.Manager', { embedded: true }),
    entries:DS.hasMany('App.Reservation', { embedded: true })
});
App.Reservation = DS.Model.extend({
    name:DS.attr('string')
});

and a handelbars view:

{{#each schedule in controller}}
<td>
  {{#each reservation in schedule.entries)}}
  <div>{{reservation.name}}</div>
  {{/each}}
</td>
{{/each}}

But with this view a've got exception

Expecting 'ID', got 'undefined'

This workaround works, but I know this is wrong way.

{{#each reservation in schedule._data.hasMany.entries}}

Any ideas?

EDIT.

After Mike Aski answer. My JSON, returning from backend.

{
  "schedules": [
    {
      "id": "476a3881-4fe8-42f5-8bdb-650d38f911e8",          
      "entries": [
        {              
          "name": "test1",
          "begin": "2012-11-22T10:00:00+06:00",
          "end": "2012-11-22T11:00:00+06:00",
          "id": "71c6da83-8ae2-4210-90f8-e65b06f819d7"
        },
        {              
          "name": "test2",
          "begin": "2012-11-22T12:00:00+06:00",
          "end": "2012-11-22T14:00:00+06:00",
          "id": "d234c8c0-66f5-4e98-b921-4472b39a98f7"
        }
      ]
    },
    {
      "id": "8d9b1539-8a1f-4a5d-acfc-5918e61e3990",          
      "entries": []
    },
    {
      "id": "a279d9a5-ea88-4012-8094-8a30125fd32b",          
      "entries": []
    }
  ]
}

回答1:


Did you ensure you have an id property in the reservations JSON objects?

You should have them, even if relations are embedded.



来源:https://stackoverflow.com/questions/13479842/ember-data-rendering-hasmany

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!