setData用变量怎么赋值?
发布于 6 年前 作者 caichao 6081 次浏览 来自 官方Issues
data: {
    team:{
      p1:{name:"", bg:0, sg:0, checked: 0},
      p2:{name:"", bg:0, sg:0, checked: 0},
      p3:{name:"", bg:0, sg:0, checked: 0},
      p4:{name:"", bg:0, sg:0, checked: 0},
    },
  switchChange(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    let py = "p1"
    let tichu = "bg"
    let value = e.detail.value == true ? 1 : 0
    that.setData({team.py.tichu:value})
    console.log(that.data.team)
// py和tichu是两个字符串,怎么用两个字符串给data.team赋值?
2 回复
 this.setData({
    [`team.${py}.${tichu}`]: id
  })
that.setData({"team.py.tichu":value})
回到顶部