question
When a QR code or a three-dimensional array is encountered during the development of a WeChat applet, the view will not be updated when updating the sub-element array of the array
analyze
Viewing the data in AppData will find that the data has been modified, but it has not been rendered on the page, which means that the memory address of the array has not been modified. This problem can be solved by changing the memory address of the data. Generally speaking, the data has been changed. Existing but not seeing the view refresh is mostly caused by this reason.
Tip: the address is a pointer
solution
Use JSON to convert the original array to JSON and then remove the escaping to achieve the purpose of changing the memory address. In theory, explaining the construction assignment should replace the memory address (you can use deconstruction assignment if you encounter this problem in react)
But it doesn't work in the WeChat developer tools. I don't know why, and someone who knows can explain it.
Tucao
This problem has existed for a long time, and the official has not resolved it.
the code
let arr = [[1,2,3,],[4,5,6],[7,8,9]];
arr = JSON.parse(JSON.stringify(arr)) ;
There will also be an element whose content address remains unchanged and the element that directly assigns an array to a variable let item = arr[index]
let arr = [[1,2,3,],[4,5,6],[7,8,9]];
let item = arr = JSON.parse(JSON.stringify(arr[index])) ;
the case
This is the page for seat selection in the cinema to be implemented. The seat is a two-dimensional array. This problem occurs when updating the state of seat selection.
The view has been updated but the page is not rendered,
just change the content address before modifying the array