this.setData 改变数组值

发布于 6 年前作者 mingli870 次浏览最后编辑 6 年前来自 ask

如图,  使用this.setData想要改变数组中某一项的值,但提示[ ]中只能为数字

或者有什么办法能改变数组seat_src某一项中name的值吗?求解

尝试把num转化为数字,还是不行

2 回复
qwan
qwan1 楼6 年前

click(e){

let that = this

let index = e.currentTarget.dataset.id;

index = index - 1;

this.setData({

[`testArr[${index}].id`]:index

},()=>{

console.log(that.data.testArr)

})

}

tianping
tianping2 楼5 年前

解决了,这样把数组写死就行了