problem description
the data obtained from the background has many layers, but it can only be assigned to the first layer through this.setState
. This will not happen if you have requested similar data before. On the one hand, I hope the gods can explain it a little bit, and hope that there can be a quick solution. Thank you very much
...
state = {
listData: {}
}
...
fetchList({
...
})
.then(data => {
console.log("data ====>", data);
this.setState({
listData: Object.assign({}, data);
}, () => {
console.log("listData =====>", this.state.listData);
})
})
The value of data depth cannot be copied correctly to data
// console.log 1
data =====> {
x1: xxx,
x2: {
x2_1: xxx,
x2_2: xxx,
},
x3: {
x3_1: xxx,
}
//...
}
// console.log 2
listData ====> {
x1: xxx,
x2: {},
x3: {},
}
everything at the beginning of the second layer is filtered as empty and cannot be assigned.