在我的 ember 应用程序中,我有一个模型:
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')
});
和车把视图:
{{#each schedule in controller}}
<td>
{{#each reservation in schedule.entries)}}
<div>{{reservation.name}}</div>
{{/each}}
</td>
{{/each}}
但是有了这个观点,就有例外
Expecting 'ID', got 'undefined'
这种解决方法有效,但我知道这是错误的方法。
{{#each reservation in schedule._data.hasMany.entries}}
有任何想法吗?
编辑。
Mike Aski 回答后。我的 JSON,从后端返回。
{
"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": []
}
]
}