小程序端调用云数据库skip分页无效
发布于 5 年前 作者 rcao 20083 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

我调用 getHistory 传了 offset 20,但是不起效果。拿到的结果还是从0条开始。

  • 预期表现

能正常分页。

  • 复现路径
  • 提供一个最简复现 Demo
export const getHistory = ({ offset = 0, limit = 20, success = null, fail = null }) => {
    getOpenid(() => {
        wx.showLoading({
            title: '加载中',
        });
 
        const db = wx.cloud.database();
        const collection = db.collection('history')
            .field({
                text: true,
                createTime: true,
            })
            .where({ _openid });
 
        offset && collection.skip(parseInt(offset)); // offset = 0 会报错
 
        collection
            .limit(limit)
            .orderBy('createTime', 'desc')
            .get({
                success: res => {
                    wx.hideLoading();

 
                    success && success({ list: res.data });
                },
                fail: err => {
                    wx.hideLoading();
                    wx.showToast({
                        icon: 'none',
                        title: '查询记录失败'
                    });
                },
            });
    });
};
1 回复

可用,我的代码问题。需要这样子更改

collection = collection.skip(parseInt(offset)); // offset = 0 会报错

回到顶部