下面是我的js代码,第一次查询可以正常获取20条,但是下拉刷新就不行。。不知道为啥,求大神指导。。。
const app = getApp()
const db = wx.cloud.database({
env: ‘nxdcs-service’
})
Page({
data: {
CRH: “”,
name: “”,
BSTPN: “”,
SupplierPN: “”,
local: “”,
tools: “”,
searchContent: “”,
todoList: [],//查询结果
todoList_nums:0 //初始数量
},
//监听input输入
watchName: function (e) {
var that = this
that.setData({
name: e.detail.value
});
},
queryTodoList() {
//测试一下能不能用
const db = wx.cloud.database()
db.collection('797').where({
name: db.RegExp({
regexp: this.data.name,
options: 'i',
})
}).get({
success: res => {
this.setData({
todoListFetched: true,
todoList: res.data,
filtered: true
})
console.log('[数据库] [查询记录] 成功: ', res)
},
fail: err => {
wx.showToast({
icon: 'none',
title: '查询记录失败'
})
console.error('[数据库] [查询记录] 失败:', err)
},
complete: () => {
wx.hideLoading()
}
})
},
onReachBottom:function(){
wx.showLoading({
title: ‘刷新中,请稍等!’,
duration:1000
})
let x=this.date.todoList_nums+20
console.log(x)
let old_date=this.date.todoList
db.collection(‘797’).where({
name: db.RegExp({
regexp: this.data.name,
options: ‘i’,
})
}).skip(x)
.get()
.then( res => {
res.date.array.forEach((item,i) => {
res.date[i].content=res.data[i].content.split(‘hy’).join(’\n’);
});
// 利用concat函数连接新数据与旧数据
// 并更新emial_nums
this.setData({
todoList: old_data.concat(res.data),
todoList_nums: x
})
console.log(res.data)
})
.catch(err => {
console.error(err)
})
console.log(‘circle 下一页’);
},
goSet: function () {
wx.navigateTo({
url: ‘…/set797/set797’,
})
},
searchTodo() {
const { searchContent } = this.data
if (!searchContent) {
this.queryTodoList()
return
}}
})