我想点击按钮重置所有选择框变成未选中。结果发现所有的值都被修改成了选中结果。 完整代码下载:https://share.weiyun.com/S7IcmbHQ
用const定义了checked值为什么会变?看下图用const定义了checked值为什么会变? [图片] [视频] [图片] 下面是代码 const haha = getApp().globalData.abc123 Page({ showModal(e) { const yiyi = haha console.log('haha值:',haha) console.log('yiyi值:',yiyi) this.setData({ checkbox: yiyi, modalName: e.currentTarget.dataset.target }) }, hideModal(e) { this.setData({ modalName: null }) }, ChooseCheckbox(e) { let items = this.data.checkbox; let values = e.currentTarget.dataset.value; for (let i = 0, lenI = items.length; i < lenI; ++i) { if (items[i].value == values) { items[i].checked = !items[i].checked; break } } this.setData({ checkbox: items }) } }) 下面是app.js保存的值 App({ globalData: { abc123: [{ value: 0, name: 200, checked: false, hot: true, }, { value: 1, name: 500, checked: false, hot: true, }, { value: 2, name: 1000, checked: false, hot: true, }, { value: 3, name: 2000, checked: false, hot: true, }, { value: 4, name: 5000, checked: false, hot: true, }, { value: 5, name: 10000, checked: false, hot: true, }], }, })
2022-01-05