不懂就问? 关于 setData性能问题
做一个购物车选择功能 当全选的时候 是 把整个购物车数据都重新setData更快 还是 逐条setData选中状态更快?
var shopCartList = [{
id: 0,
name: "123",
productList: [{
id: 0,
name: "123",
isChecked: false,
},
{
id: 0,
name: "123",
isChecked: false,
},
{
id: 0,
name: "123",
isChecked: false,
},
{
id: 0,
name: "123",
isChecked: false,
}
]
}, {
id: 0,
name: "123",
productList: [{
id: 0,
name: "123",
isChecked: false,
},
{
id: 0,
name: "123",
isChecked: false,
},
{
id: 0,
name: "123",
isChecked: false,
},
{
id: 0,
name: "123",
isChecked: false,
}
]
}]
//全部替换
shopCartList.forEach((value, index) => {
value.productList.forEach((val, ind) => {
val.isChecked = true
})
})
this.setData({
shopCartList: shopCartList
})
//逐条替换
shopCartList.forEach((value, index) => {
value.productList.forEach((val, ind) => {
this.setData({
["shopCartList[" + index + "].productList["+ ind +"].isChecked"]: true
})
})
})