文档服务 API:结果的排序和分页
🌐 Document Service API: Sorting and paginating results
文档服务 API 提供对查询结果进行排序和分页的功能。
🌐 The Document Service API offers the ability to sort and paginate query results.
排序
🌐 Sort
要对文档服 务 API 返回的结果进行排序,请在查询中包含 sort 参数。
🌐 To sort results returned by the Document Service API, include the sort parameter with queries.
按单个字段排序
🌐 Sort on a single field
要根据单个字段对结果进行排序:
🌐 To sort results based on a single field:
示例请求
const documents = await strapi.documents("api::article.article").findMany({
sort: "title:asc",
});
示例响应
[
{
"documentId": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"documentId": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ...
]
按多个字段排序
🌐 Sort on multiple fields
要对多个字段进行排序,请将它们全部传递到一个数组中:
🌐 To sort on multiple fields, pass them all in an array:
示例请求
const documents = await strapi.documents("api::article.article").findMany({
sort: [{ title: "asc" }, { slug: "desc" }],
});
示例响应
[
{
"documentId": "cjld2cjxh0000qzrmn831i7rn",
"title": "Test Article",
"slug": "test-article",
"body": "Test 1"
// ...
},
{
"documentId": "cjld2cjxh0001qzrm5q1j5q7m",
"title": "Test Article 2",
"slug": "test-article-2",
"body": "Test 2"
// ...
}
// ...
]