请问怎么在page页面里面调用数据库里的数据那些呢,不需要修改删除。还有一个页面是搜索 怎么结合云开发实现呢?
页面就是直接查数据库 ,具体看文档
// 数据表parking 查询id的数据更新status字段, 更新
getApp().globalData.db.collection('parking').doc(id).update({ data: { status:0 } }).then(res => {
wx.showToast({
title: '操作成功!',
mask: true,
icon: 'success'
})
setTimeout(() => {
wx.navigateBack()
}, 1500)
}).catch(console.error)
// 查询获取数据列表 参考
const db = getApp().globalData.db
const _ = db.command
const query = { _openid, oId: _.exists(TabCur == 1) }
if (TabCur == 2) query.status = 4
else if (TabCur == 3) {
query.status = 3
delete query._openid
} else if (TabCur == 0) query.status = _.eq(1).or(_.eq(0))
title && (query.title = db.RegExp({ regexp: title, options: 'i', }))
db.collection('parking').limit(size).skip((page - 1) * size).where(query).get().then(({ data = [] }) => {
wx.stopPullDownRefresh()
wx.hideLoading()
const next = data.length == size
this.setData({ next })
list = list.concat(data)
that.setData({ list })
if (page == 1 && !title && !none && list.length == 0) that.setData({ none: true })
}).catch(e => {
wx.showToast({
title: '获取数据失败!',
mask: true,
icon: 'none'
})
})