getOrderList(){ wx.cloud.database().collection('shop_orders') .where({ status:Number(this.data.status), _openid: app.globalData.openid }) .orderBy('time','desc') .get() .then(res=>{ console.log(res) this.setData({ orderList:res.data }) }) }, pay(event){ let index = event.currentTarget.dataset.index console.log(index) wx.showModal({ title:'提示', content:'是否支付商品价格' + this.data.orderList[index].totalMoney + '元', confirmText:'支付' }) .then(res=>{ console.log(res)
时间: 2023-06-16 12:06:20 浏览: 46
这段代码是一个小程序中的云函数,用于获取订单列表和支付订单。首先,在getOrderList()函数中,它从云数据库中的'shop_orders'集合中获取特定状态和特定openid的订单列表,并按时间降序排列。然后将结果存储在orderList中以供后续使用。
在pay()函数中,它首先获取当前点击的订单在orderList中的索引,然后显示一个确认支付的模态框,提示用户支付该订单的总金额。一旦用户点击确认支付,代码将执行相应的支付逻辑。
相关问题
wx.cloud.database().collection().doc()
wx.cloud.database().collection().doc() 是小程序云开发中用于操作数据库的方法之一。这个方法用于获取指定集合中的指定文档数据。
在这个方法中,wx.cloud.database() 表示获取云数据库的实例,collection() 表示指定要操作的集合,doc() 表示指定要操作的文档。
你可以在 doc() 方法中传入一个文档的 ID 或者一个查询条件,来获取指定的文档数据。
例如,你可以使用类似的代码来获取一个指定 ID 的文档数据:
wx.cloud.database().collection('collectionName').doc('documentID').get({
success: function(res) {
console.log(res.data);
}
});
其中,'collectionName' 是指定的集合名称,'documentID' 是指定的文档 ID。
请注意,这是一个简化的示例,实际使用时需要根据具体情况进行调整。
wx.cloud.database().collection('shop_goods') .where({ isHome:true, status:true }) 我还想添加一个检索条件 sunmtotal>0 我该怎么写?
你可以在 where 方法中再加入一个条件,类似这样:
```javascript
wx.cloud.database().collection('shop_goods')
.where({
isHome: true,
status: true,
sumtotal: _.gt(0) // _.gt 表示大于的意思
})
```
其中,`_.gt` 是一个 Lodash.js 的方法,表示大于。这样就可以筛选出 `sunmtotal` 大于 0 的数据了。