js中的data 中
data: {
type:'',
normallist:[]
}
getType(e){
var type = e.currentTarget.data.type normallist
console.log(this.data.type); ''
console.log(this.data[type]); this.data.normallist
var arr = this.data[type]
此处可以进行一系列操作.......
this.setData({
[type]:arr
})
},
如图所示。想对点击项得数组进行操作,如果直接使用this.data.type 那么直接获取得就是data中type,但是我这里想取的是点击项对应的数组,所以使用this.data[type]就可以直接使用变量名(type),获取的就是normallist 这个数组。赋值时如果是变量就[变量名]即可。