赋值操作没明白
发布于 6 年前 作者 maoming 1173 次浏览 来自 问答

源码:

bindMultiPickerColumnChange: function (e) {

var jectMul = new Array;

var data = {

objectMultiArray: this.data.objectMultiArray,

multiIndex: this.data.multiIndex

};

data.multiIndex[e.detail.column] = e.detail.value;

var that = this;

wx.request({

url: AppData.AppConfigData.weburl + ‘/WxForm/WebClass2.html’,

data: { cid: data.objectMultiArray[0][e.detail.value].id },

method: ‘GET’,

header: { ‘content-type’: ‘application/json’ },

success: function (res) {

that.setData({

jectMul: res.data

})

}

});

this.data.objectMultiArray[1] = this.data.jectMul;

console.log(‘asdasd值22为’, this.data);

console.log(‘asdasd值23332为’, jectMul);

data.multiIndex[1] = 0;

this.setData(this.data);

},

这个是一个二级联动分类选择器。选择一级后,根据ID读数据库显示二级。

this.data  显示 jectMul  是实时数据

this.data.jectMul  是不确定数据!!


怎么才能使  this.data.objectMultiArray[1] = this.data.jectMul;   这个等式成立。每次调用都准确替换objectMultiArray的值

2 回复

console.log(this.data);

console.log(this.data.jectMul);

这样两次输出的结果不一致!!!

jectMul  就是  this.data  中的一项

data.objectMultiArray[0][e.detail.value].id    每次请求的ID是正确的。就是不明白为什么,返回的数据也对。但是到了小程序端,this.data.jectMul   这样读取,就很乱,有可能没有,也有可能是上一个ID的数据。反正就是乱显示

回到顶部