onUpdate: function (e) {
var orderInfoList = this.data.orderInfoList;
var checked = true;
for(var i=0; i<orderInfoList.length; i++) {
if (orderInfoList[i].selected) {
if (orderInfoList[i].orderSize > orderInfoList[i].stockQuantity) {
wx.showToast({
icon: “none”,
title: ‘商品库存数量不足哦’,
})
}
wx.cloud.callFunction({
name: ‘updateOrderByOrderID’,
data: {
orderID: orderInfoList[i].orderID
}
}).then(async function (res){
// 商品表 库存数-订单数
console.log(orderInfoList[i].productID + “商品表 库存数-订单数”)
wx.cloud.callFunction({
name: ‘updateProductByID’,
data: {
productID: orderInfoList[i].productID,
// 库存数 - 订单数
stockQuantity: orderInfoList[i].stockQuantity - orderInfoList[i].orderSize,
}
}).then(res =>{
wx.navigateTo({
url: ‘…/order’
})
}).catch(err =>{
wx.showToast({
icon: “none”,
title: ‘更新商品表失败’,
})
})
}).catch(err =>{
wx.showToast({
icon: “none”,
title: ‘更新订单表失败’,
})
})
checked = false;
}
}
if (checked) {
wx.showToast({
icon: “none”,
title: ‘要先选中商品哦’,
})
}
}
第一层循环时,console.log中变量i就变成2了,为什么呀,怎么解决呢?
5 回复