微信小程序 怎么动态的赋值呢?


this.setData({
    "bottomTip[this.data.nav.currentIndex].state": 2
})

this.data.nav.currentIndex 是不确定的

有办法这样赋值吗?

阅读 4.2k
3 个回答
this.setData({
    [`bottomTip[${this.data.nav.currentIndex}].state`]: 2
})
var state= "bottomTip["+this.data.nav.currentIndex+"].state";
this.setData({
   [state]: 2
})

你这样的赋值逻辑有点奇怪,应该是这样吧

data: {
   bottomTip:[]
  }

changeData: function(){
    bottomTip[this.data.nav.currentIndex].state = 2
    this.setData({
        bottomTip: bottomTip
    })
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题