非常简单(我希望)。我希望能够使用 API 端点并让它只返回指定的字段。IE类似这样的东西
http://localhost:1337/api/reference?select=["name"]
Run Code Online (Sandbox Code Playgroud)
理想情况下会返回某种形式的东西
[{"name": "Ref1"}]
Run Code Online (Sandbox Code Playgroud)
不幸的是,情况并非如此,实际上它返回以下内容。
http://localhost:1337/api/reference?select=["name"]
Run Code Online (Sandbox Code Playgroud)
如果我决定一次加载 10、20、30 或更多记录,这在任何现实世界中都会立即成为问题,我最终加载了所需数据的 50 倍。更多的带宽用完,加载时间变慢等。
我是如何解决这个问题的:
module.exports = {
findPaths: async ctx => {
const result = await strapi
.query('contributor')
.model.fetchAll({ columns: ['slug'] }) // here we wait for one column only
ctx.send(result);
}
}
Run Code Online (Sandbox Code Playgroud)
{
"method": "GET",
"path": "/contributors/paths",
"handler": "contributor.findPaths",
"config": {
"policies": []
}
},
Run Code Online (Sandbox Code Playgroud)
就是这样。现在它只显示slug
所有贡献者记录中的字段。
http://your-host:1337/contributors/paths
Run Code Online (Sandbox Code Playgroud)
Strapi 中尚未实现此功能。作为补偿,最好的选择可能是使用 GraphQL ( http://strapi.io/documentation/graphql )。
请随意创建问题或提交拉取请求:https://github.com/wistityhq/strapi
归档时间: |
|
查看次数: |
10382 次 |
最近记录: |