在页面中有一个数组和一个对象
data: {
cityArr: ['北京', '上海', '广州'],
region: {
province: '广东省',
city: '广州市',
district: '天河区'
},
}
需求1:把数组中的“上海”改成“深圳”
解决方法:
// 1
this.setData({
['cityArr[1]']: '深圳'
})
// 2
let data = 'cityArr[1]';
this.setData({
[data]: '深圳'
})
需求2:把对象中district属性值改成“海珠区”
解决方法:
// 1
this.setData({
['region.district']: '海珠区'
})
// 2
let data = 'region.district';
this.setData({
[data]: '海珠区'
})