Do a little applet to use setData summary, if wrong, please feel free to point out, Thanks ♪ (· ω ·) Techno
// Example data:
data:{
user:'young',
obj:{
name: 'blue dandelion',
age:'17'
},
arr:[{
name:'Lucy',
age: '18'
},{
name: 'Pinellia',
age:'19'
}]
}
First, the direct modification of a property data
this.setData({
user:'007'
});
Second, the data in the array or modify the properties of an object
this.setData({
'obj.age': '16'
})
Third, the selective change according to the conditions
// This example assumes a property value corresponding to the change of index
var index = e.target.dataset.index; // assumed to be corresponding to the object attribute data-index
var temp_str='arr['+index+'].age';
this.setData({
[temp_str]:'18'
});