- 需求的场景描述(希望解决的问题)
发布产品时需要消耗个人积分,所以需要在个人表中更新,扣除积分成功才会在清单表中记录,否则删除刚才的产品发布记录
let $result = { bool: false , message: '提交失败!' }; try { await db.collection( 'Goods' ).add({ data: e.iData }).then(res => { await db.collection( 'Users' ).doc(id).update({ data: { _goods: _.unshift(res._id), _scores: _.inc(-$cost) } }).then(res => { await db.collection( 'Score' ).doc(id).update({ data: { _history: _.unshift({ _type: '支出' , _scores: -$cost, _date: db.serverDate() }) } }).then(res => { $result.bool = true ; $result.message = '提交成功!' ; }) }). catch (err => { await db.collection( 'Goods' ).doc(res._id).remove(); }) }); } catch (err){ console.log(err); }finally{ return $result; } |
- 希望提供的能力
怎么样写才不会报错?
你的问题是这样的,async只能修饰主函数,并不能修饰回调函数 ,你下面每一次使用await的时候都是对回调函数而言的,但是你没有对回调函数进行async声明导致编译器不能识别await 你可以这样写 async res=>{
await
}
这样就可以调用了
谢谢帮助,解决了。
官方文档给了很多坑 hhhh 慢慢踩吧
是的,教程很多都只是很简单的,不够详细,对于我这种非计算机专业的人来说初学起来真的太难了。
之前连doc()括号里面都不知道写什么,后面问了很多人才知道那里面就是_id,教程中没有说明。
你能说的清楚点吗?是不是不能这样嵌套?回滚又是怎么回事?
云函数里面写下 写错了然后回滚。现在没事务所以得自己记录失败
现在 输出的记录是 Unexpected identifier