- 第一层循环时,console.log中变量i就变成2了,为什么呀,怎么解决呢?
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: '要先选中商品哦', }) } }
2019-11-26 - 数组中变量未定义问题,不知道该怎么解决啦?
数据: orders[{ clientID:1001 productID:10001 },{ clientID:1001 productID:10002 },{ clientID:1002 productID:10001 }] // 初期处理 data: { editOrderInfoList:[{ clientID:'', userName:'', productList:[] }] } // onLoad处理 onLoad: function (options) wx.cloud.callFunction({ name: 'searchAllOrder' }).then( async function(res) { const orders = res.result.data; var clientIDList = []; var j=0 for (let i = 0; i < orders.length; i++) { if (clientIDList.indexOf(orders[i].clientID) < 0) { // 客户信息 const clientResult = await db.collection('client').where({ clientID: orders[i].clientID }).get() clientIDList.push(orders[i].clientID); _this.data.editOrderInfoList[j].clientID = clientResult.data[0].clientID; _this.data.editOrderInfoList[j].userName = clientResult.data[0].userName; j++; } } 现象:J=1,clientID=1002的时候出异常,TypeError: Cannot read property 'clientID' of undefined 大概是”_this.data.editOrderInfoList[j].clientID“出问题,不知道怎么解决啦,大神们
2019-11-19 - 云函数更新db返回result=null,为什么?
// 云函数入口文件 const cloud = require('wx-server-sdk') cloud.init() const db = cloud.database()//打开数据库连接 // 云函数入口函数 exports.main = async (event, context) => { const wxContext = cloud.getWXContext() try{ db.collection("client").doc(event.id).update({ data: { userName: event.userName, alias: event.alias, mobile: event.mobile, address: event.address, createTime: db.serverDate() } }) } catch (e) { console.error('err:', e) } }
2019-11-05