数据:
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“出问题,不知道怎么解决啦,大神们
OK啦,你们都好厉害
// 初期处理
data: {
editOrderInfoList:[]
}
---------=========
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.push({
clientID: clientResult.data[0].clientID,
userName: clientResult.data[0].userName,
productList: []
})
}
editOrderInfoList 只有一项,j为1时当然是undefined