let sdata={
'a':{
'has':true,
'content':[]
},
'b':{
'has':true,
'content':[]
},
let chang=sdata['a'].content
chang.push(1)
index是个变量,要添加的key是不确定a还是b
let schang='sdata['+index+'].content'
that.setData({
schang:chang,
})
that.setData({
'schang':chang,
})
都不起作用,谢谢
let content=that.data.sdata.a.content content.push(1) that.setData({ "sdata['a'].content": content })
that.setData({
"sdata['"+index+"'].content": content
})
"'sdata['+index+'].content'":chang 这种你实际跑下会发现报错Only digits (0-9) can be put inside [] in the path string 'sdata['+index+'].content':change单独拼编译都过不去
至于用个变量等于'sdata['+index+'].content',编译是可以通过,但是无效果
this.setData({ sdata: JSON.parse(JSON.stringify(this.sdata)), })