我的方法成功处理了每次只返回20条数据的限制,但是上滑加载更多的时候,为什么加载出来的数据是重复第一次的,而不是新数据啊?
云函数
async function getGoods() {
const MAX_LIMIT = 100
const countResult = await db.collection('Goods').count()
const total = countResult.total
const batchTimes = Math.ceil(total / 100)
const list = []
for (let i = 0; i < batchTimes; i++) {
const promise = db.collection('Goods').aggregate()
.lookup({
from: 'User',
localField: 'adminId',
foreignField: '_id',
as: 'adminInfo',
})
.skip(i * MAX_LIMIT).limit(MAX_LIMIT).end()
list.push(promise)
}
return (
await Promise.all(list)).reduce((acc, cur) => ({
data: acc.data.concat(cur.data),
errMsg: acc.errMsg,
}))
}
index.js
_fecthGoods: function () {
wx.cloud.callFunction({
name: 'goodsMgt',
data: {
req_type: 'Selection'
}
}).then(res => {
console.log(res)
let goodsList = res.result.list
this.setData({
goodsList: goodsList
})
wx.lin.renderWaterFlow(goodsList);//瀑布流组件
console.log("商品列表:", this.data.goodsList)
})
},
onReachBottom: function () {
this._fecthGoods()
wx.stopPullDownRefresh({
success: (res) => {
console.log(res)
},
})
},
https://developers.weixin.qq.com/community/develop/article/doc/0008ea04120a18f6988b86d065b013