- 存在变量名相同的情况,后边的会覆盖前面,但是C为什么会等于6?
Page({ data: { obj1: { a: 1, b: 2 }, obj2: { b: 3, c: 4 }, a: 5 } }) 最终组合成的对象是 {a: 5, b: 3, c: 6}。
2021-10-13 - 初学者,checkboxChange中使用this引用的变量,一个有值,一个显示undefined?
错误信息: 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 }) } })
2021-09-15