【发布时间】:2016-09-06 15:51:05
【问题描述】:
我正在使用 jsonapi 指令在 ember.js 应用程序和 API 之间建立连接。我有一个 track,它可能有 50 个或更多 comments,我需要将它们加载到路由上以执行一些逻辑。
这是 API 的示例响应:
{
"data": {
"id": 1,
"type": "track",
"attributes": {
"name": "XPTO"
},
"relationships": {
"comment": {
"data": [
{"id": 1, "type": "comment"}
]
}
}
},
"include": [
{
"id": 1,
"type": "comment",
"attributes": {
"text": "Lorem ipsum..."
}
}
]
}
现在想象一下它有 50 个 cmets,每次调用都发出请求会非常消耗。如果我在带有each 循环的视图中执行此操作,它不会发出所有请求,但我尝试在路由中访问它,它将发出所有请求。如何使用以下代码实现?
this.store.findRecord('track', 1).then((t) => {
// logic here
// I tried this but it would make all the requests too
t.get('comments');
})
【问题讨论】:
标签: ember.js ember-data json-api