setData以路径更新的方式增加数组元素时,数组长度不会正确更新
- 当前 Bug 的表现(可附上截图) 数组元素增加了,数组长度没变。 - 预期表现 数组长度正确变化 - 复现路径 https://github.com/NervJS/taro/issues/882#issuecomment-440127031 - 提供一个最简复现 Demo [代码]<!-- index.wxml -->[代码][代码]<[代码][代码]block[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]"container"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]text[代码] [代码]wx:for[代码][代码]=[代码][代码]"{{contents}}"[代码] [代码]wx:for-item[代码][代码]=[代码][代码]"item"[代码][代码]>{{item.text}}</[代码][代码]text[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]bindtap[代码][代码]=[代码][代码]"add"[代码][代码]>add line by path</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]bindtap[代码][代码]=[代码][代码]"add2"[代码][代码]>add line by replace array</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]bindtap[代码][代码]=[代码][代码]"log"[代码] [代码]data-content[代码][代码]=[代码][代码]"{{contents}}"[代码] [代码]data-content-length[代码][代码]=[代码][代码]"{{contents.length}}"[代码][代码]>show log</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]disabled[代码][代码]=[代码][代码]"{{contents.length ? false : true}}"[代码][代码]>{{contents.length}}</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]block[代码][代码]>[代码][代码]let i = 0[代码] [代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]contents: [],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]add () {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码][`contents[${i++}]`]: { text: [代码][代码]'test'[代码] [代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]add2() {[代码][代码] [代码][代码]this[代码][代码].setData({[代码][代码] [代码][代码]contents: [...[代码][代码]this[代码][代码].data.contents, { text: [代码][代码]'test'[代码] [代码]}][代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]log (ev) {[代码][代码] [代码][代码]console.log({[代码][代码] [代码][代码]contentLength: ev.currentTarget.dataset.contentLength,[代码][代码] [代码][代码]content: ev.currentTarget.dataset.content[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码]})[代码]