使用 DS.RESTAdapter :
在应用中给出两个模型App.Calendar = DS.Model.extend({
reservations: DS.hasMany("reservation", { async: true })
});
App.Reservation = DS.Model.extend({
date: DS.attr("date"),
calendar: DS.belongsTo("calendar")
});
有效负载如:
/ API /日历/ 1:
{
"calendar": {
"id": 1,
"reservations": [],
"links": {
"reservations": "/api/calendar/1/reservations"
}
}
}
/ API /日历/ 1 /保留:
{
"reservations": [
{
"id": 1,
"date": "10/01/2014"
}
]
}
为什么日历模型上的预订数组没有延迟加载?
答案 0 :(得分:3)
你的json不应该定义两次保留
{
"calendar": {
"id": 1,
"links": {
"reservations": "/api/calendar/1/reservations"
}
}
}