以下代码,为什么会查询失败,返回null,哪里写错了,请指教,谢谢。
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
const thisOpenId = wxContext.OPENID
const db = cloud.database()
db.collection('staff').where({
staffOpenId: thisOpenId
}).get({
success: function (res) {
return res.data
}
})
}
return await db.get()
if(result) {
return {};
}
const wxContext = cloud.getWXContext()
const thisOpenId = wxContext.OPENID
const db = cloud.database()
let result = 'init'
const action = await db.collection('staff').where({
staffOpenId: thisOpenId
}).get({
success: function (res) {
//这里做逻辑判断,决定返回什么内容
result = [{
thisOpenId: thisOpenId,
isPass: true
}]
}
});
if (action) {
return result
}
}
我反正只要看到云函数里有success,就知道会错。
const wxContext = cloud.getWXContext()
const thisOpenId = wxContext.OPENID
const db = cloud.database()
let result
const action = await db.collection('staff').where({
staffOpenId: thisOpenId
}).get({
success: function (res) {
result = [{
thisOpenId: thisOpenId,
isPass: true
}]
}
});
if (action) {
return result
}
}