错误信息:
ledDeviceType.js? [sm]:50 this.data.gGlobalData.checkboxItems: (3) [{…}, {…}, {…}]
ledDeviceType.js? [sm]:51 this.data.gSystemConfigTable.gLedDeviceModelType: undefined
ledDeviceType.js? [sm]:52 values: (2) ["2", "1"] Default systemConfigTable.ledDeviceModelType: undefined
VM1506 WAService.js:2 TypeError: Cannot set property 'checked' of undefined
at vt.checkboxChange (ledDeviceType.js? [sm]:55)
at Object.o.safeCallback (VM1506 WAService.js:2)
。。。。
=======================================================================================
代码:
// ledDeviceType.js
Page({
onShareAppMessage() {
return {
title: 'checkbox',
path: 'page/component/pages/checkbox/checkbox'
}
},
data: {
gSystemConfigTable: {
// 全局配置参数信息,保存参数,用于后续设置
gLedDeviceModelType: 2,
},
gGlobalData: {
checkboxItems: [
{value: '0', name: '1111111'},
{value: '1', name: '1111112'},
{value: '2', name: '1111113'},
]
}
},
// 选中点击时触发该事件
checkboxChange (e) {
let values = e.detail.value;
let checkboxItems = this.data.gGlobalData.checkboxItems;
let systemConfigTable = {
ledDeviceModelType: this.data.gSystemConfigTable.gLedDeviceModelType,
}
console.log('this.data.gGlobalData.checkboxItems: ', this.data.gGlobalData.checkboxItems)
console.log('this.data.gSystemConfigTable.gLedDeviceModelType: ', this.data.gSystemConfigTable.gLedDeviceModelType)
console.log('values: ', values, 'Default systemConfigTable.ledDeviceModelType: ', systemConfigTable.ledDeviceModelType)
// 赋初值,取消勾选情况下使用默认值
checkboxItems[systemConfigTable.ledDeviceModelType].checked = true
// ..............................
this.setData({
checkboxItems, checkboxItems,
gSystemConfigTable: systemConfigTable
})
}
})
看错误提示,就是这边报undefined,因为小程序修改值不是这样改的,所以在报错。小程序中修改数组中的某个值,得用如下语句:this.setData({
["couponList[" +index + "].isCollect"]: 1
}),而且systemConfigTable.ledDeviceModelType也在报undefined啊,自己找错啊,一步步来。而且建议提问附上代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html,这是代码片段创建方法),代码片段会便于官方人员查看和大家查看,