在Strapi中实施分页
async function find(ctx) {
return await strapi.services.article.find(ctx.query)
}
这是我的控制器,
resolver: async (obj, options, ctx) => {
const result = await strapi.query('active').model.find({ article_id: obj.id});
return result.length > 0;
}
这是我的解析器
,我在strapi后端上设有它,我正在尝试弄清楚如何进行分页。因为有很多方法可以解决,并且没有很好的记录,所以我不确定我们能做什么。这是使用猫鼬吗?
resolver: async (obj, options, ctx) => {
const result = await strapi.query('active').model.find({ article_id: obj.id}).limit(obj.limit).offset(obj.offset);
return result.length > 0;
}
是否可以这样做,因为我假设正在使用它的猫鼬?如果没有,我们如何才能更改解析器来分页?
async function find(ctx) {
return await strapi.services.article.find(ctx.query)
}
This is my controller
resolver: async (obj, options, ctx) => {
const result = await strapi.query('active').model.find({ article_id: obj.id});
return result.length > 0;
}
This is my resolver
I have this on my strapi backend and I am trying to figure out how to do pagination. Because there are so many ways to go about it and it's not documented very well, I am not sure what we can do. Is this using Mongoose and also, how do you send the data from the controller to the resolver exactly?
resolver: async (obj, options, ctx) => {
const result = await strapi.query('active').model.find({ article_id: obj.id}).limit(obj.limit).offset(obj.offset);
return result.length > 0;
}
Is it possible to do this since I am assuming it is mongoose that's being used? If not, how can we change the resolver to paginate the articles?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于Strapi V3,您可以使用类似的东西:
for strapi v3, you can use something like this:
可以使用分页上构建的查询引擎API:
https://docs.strapi.io/developer-docs/latest/latest/developer-resources/database-database-apise-apis-epis-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reference-reperferen时候/query-eengine/order-pagination一下.html#分页。
It is possible to use the Query Engine API that has build in pagination:
docs: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/query-engine/order-pagination.html#pagination.