如何仅返回Strapi中选定的某些字段?
问题描述:
非常简单(我希望)。我希望能够使用API端点并使其仅返回指定的字段。 I.E.像这样如何仅返回Strapi中选定的某些字段?
http://localhost:1337/api/reference?select=["name"]
在理想情况下交回
[{"name": "Ref1"}]
的一些不幸的情况并非如此,而实际上它返回以下。
[
{
"contributors": [
{
"username": "aduensing",
"email": "[email protected]",
"lang": "en_US",
"template": "default",
"id_ref": "1",
"provider": "local",
"id": 1,
"createdAt": "2016-07-28T19:39:09.349Z",
"updatedAt": "2016-07-28T19:39:09.360Z"
}
],
"createdBy": {
"username": "aduensing",
"email": "[email protected]",
"lang": "en_US",
"template": "default",
"id_ref": "1",
"provider": "local",
"id": 1,
"createdAt": "2016-07-28T19:39:09.349Z",
"updatedAt": "2016-07-28T19:39:09.360Z"
},
"updatedBy": {
"username": "aduensing",
"email": "[email protected]",
"lang": "en_US",
"template": "default",
"id_ref": "1",
"provider": "local",
"id": 1,
"createdAt": "2016-07-28T19:39:09.349Z",
"updatedAt": "2016-07-28T19:39:09.360Z"
},
"question": {
"createdBy": 1,
"createdAt": "2016-07-28T19:41:33.152Z",
"template": "default",
"lang": "en_US",
"name": "My Question",
"content": "Cool stuff, huh?",
"updatedBy": 1,
"updatedAt": "2016-07-28T19:45:02.893Z",
"id": "579a5ff83af4445c179bd8a9"
},
"createdAt": "2016-07-28T19:44:31.516Z",
"template": "default",
"lang": "en_US",
"name": "Ref1",
"link": "Google",
"priority": 1,
"updatedAt": "2016-07-28T19:45:02.952Z",
"id": "579a60ab5c8592c01f946cb5"
}
]
如果我决定一次加载10,20,30,或多个记录这立即成为真正的世界背景有问题,我并最终装50的时候,我需要的数据。更多带宽用完,加载时间更慢等。
答
此功能尚未在Strapi中实施。为了弥补,最好的选择是使用GraphQL(http://strapi.io/documentation/graphql)。
随意创建问题或提交拉请求:https://github.com/wistityhq/strapi