zzl00770

导航

getdata 按条件查询数据

//云端代码
const db = uniCloud.database()
exports.main = async (event, context) => {
    const collection = db.collection(event.name)
    const res = await collection.where(event.data).get()
    return res
};
//前台代码
getdata() {
    uni.showLoading({
        title: '处理中...'
    })
    uniCloud.callFunction({
        name: 'getdata',
        data: {
            name: 'unicloud-test',
            data: {
                "leixing": "分类"
            }
        }
    }).then((res) => {
        uni.hideLoading()
        uni.showModal({
            content: `查询成功,获取数据列表为:${JSON.stringify(res.result)}`,
            showCancel: false
        })
        console.log(res)
    }).catch((err) => {
        uni.hideLoading()
        uni.showModal({
            content: `查询失败,错误信息为:${err.message}`,
            showCancel: false
        })
        console.error(err)
    })
},

 

posted on 2024-01-23 22:00  品味人生nuiapp  阅读(4)  评论(0编辑  收藏  举报