//商家点击发货 send(event){ let index = event.currentTarget.dataset.index let that = this wx.showModal({ title: '提示', content: '是否确认发货', complete: (res) => { if (res.cancel) { wx.showToast({ icon:'error', title: '取消失败', }) } if (res.confirm) { //取消成功后 将该订单状态转换到 status = -2 吧 并不显示到待支付页面 db.collection('shop_order').doc(that.data.orderList[index]._id) .update({ data:{ status:1 } }) .then(res=>{ wx.showToast({ icon:'success', title: '发货成功成功', }) this.getOrderList() //这里要有一个退款函数 需要将商业执照办理 }) .catch(res=>{ console.log("更新失败",res) }) //取消成功后需要刷新数据 } } }) }, 显示更新成功 但updated:0,数据库没有改变
时间: 2024-02-20 15:58:55 浏览: 14
根据你提供的代码,我发现你在更新数据时将 status 更改为了 1,而不是 -2,这可能是导致更新失败的原因之一。你需要将该订单状态转换到 status = -2,而不是 status = 1。此外,如果你需要更改数据库中的数据,你需要在更新数据的时候传入新的数据对象,而你的代码中并没有这样做。因此,你需要将代码修改为以下内容:
```
db.collection('shop_order').doc(that.data.orderList[index]._id)
.update({
data: {
status: -2
}
})
.then(res => {
wx.showToast({
icon: 'success',
title: '发货成功成功',
})
this.getOrderList() //这里要有一个退款函数 需要将商业执照办理
})
.catch(res => {
console.log("更新失败", res)
})
```
这样应该可以成功更新数据库并将状态更改为 -2。
相关问题
let index = e.currentTarget.dataset.index; 代码解释
`let index = e.currentTarget.dataset.index;` 这行代码主要是获取当前点击的元素的 `index` 值。在这里,`e` 是事件对象,`currentTarget` 是事件发生的当前元素,`dataset` 是元素上自定义属性的集合,`index` 是自定义属性的一个属性名。
举个例子,如果我们在页面上有如下元素:
```
<button data-index="1">按钮1</button>
<button data-index="2">按钮2</button>
```
当我们点击“按钮1”时,事件对象 `e` 会传递给 `tabClick` 函数,`currentTarget` 就是“按钮1”,`dataset` 就是 `{"index": "1"}`,所以 `e.currentTarget.dataset.index` 就是获取 `index` 的值,即为 1。同理,当我们点击“按钮2”时,`e.currentTarget.dataset.index` 的值就是 2。
up(event){ console.log(event.currentTarget.dataset.index) let index=event.currentTarget.dataset.index wx.cloud.database().collection('product').doc(this.data.product[index]._id).update({ data:{ status:true } }).then(res=>{ wx.showToast({ title: '已上架', }) this.productList() }) },解释
这是一段微信小程序中的 JavaScript 代码,主要功能是在用户点击某个元素的时候,更新云数据库中的某个数据,然后重新加载产品列表并显示一个提示框。
具体解释如下:
1. 当用户点击某个元素时,会触发一个事件,该事件的参数会被传递到一个名为 `up` 的方法中。
2. 这个方法首先通过 `event.currentTarget.dataset.index` 获取当前元素的索引,然后通过这个索引找到对应的产品 ID。
3. 接着,使用 `wx.cloud.database().collection('product').doc(this.data.product[index]._id).update()` 方法更新数据库中的数据,将该产品的 `status` 字段设为 `true`,表示已上架。
4. 如果更新成功,在页面上显示一个提示框,提示用户该产品已上架。
5. 最后调用 `this.productList()` 方法重新加载产品列表,以便用户能够看到更新后的状态。