在Strapi中实施分页

发布于 2025-02-07 18:39:22 字数 685 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎夜雨 2025-02-14 18:39:22

对于Strapi V3,您可以使用类似的东西:

const result = await strapi.query("model").find({
      id: id,
      _start: page > 0 ? (page - 1) * pageSize : 0,
      _limit: pageSize,
      _sort: "created_at:desc",
});

for strapi v3, you can use something like this:

const result = await strapi.query("model").find({
      id: id,
      _start: page > 0 ? (page - 1) * pageSize : 0,
      _limit: pageSize,
      _sort: "created_at:desc",
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文