1***@qq.com
1***@qq.com
  • 发布:2021-04-19 23:33
  • 更新:2021-04-21 08:54
  • 阅读:462

用云函数调不到数据,帮我看看哪出问题了?

分类:uniCloud

前端页面
onLoad(option) {
uniCloud.callFunction({
name:'detail',
data:option,
success: (res) => {
console.log(res)
}
})
}

云函数
'use strict';
exports.main = async (event, context) => {
//event为客户端上传的参数
const db = uniCloud.database();
let res = await db.collection('马赛克').where({
_id:event
}).get()
return res
};

调用结果

明明有数据的啊,为啥调不出呢,是我哪里写错了吗?

2021-04-19 23:33 负责人:无 分享
已邀请:
hws007

hws007 - 我就是我!

_id:event

event是对象

  • 1***@qq.com (作者)

    我用event. _Id 也是一样的


    2021-04-20 07:26

1***@qq.com

1***@qq.com (作者) - 蔡定交

我用event. _Id 也是一样的

每日必学网

每日必学网

处理好了没有

hws007

hws007 - 我就是我!

你先输出下console.log(event),看看event是什么键值,再给于查找

雷峰

雷峰

页面onLoad参数是对象,传到云函数后event就是onLoad的参数对象,就看你页面传参是怎么传的了。比如你的页面是

uni.navigateTo({  
  url:"/pages/index/index?oid=xxx"  
})

那你查询的_id就是event.oid。另外云函数条件只查询_id可以用doc方法代替where:

let res = await db.collection('马赛克').doc(event.oid).get()
  • 1***@qq.com (作者)

    解决了,谢谢


    2021-04-22 20:48

该问题目前已经被锁定, 无法添加新回复