微信小程序如何更新数组对象下某个属性的的值

我的data

data:{
    outList:[
      {
        title:'业绩统计',
        result: ['实时业绩', '大区业绩排行榜'],
        innerList: ['实时业绩','业绩趋势图', '大区业绩排行榜', '门店业绩排行榜', '日业绩统计'],
      },
      {
        title: '业绩统计',
        result: ['商品销售排行(图)'],
        innerList: ['商品销售排行(图)', '商品销售配排行(表)', '商品销量同比提升排行']},
      {
        title:'库存统计',
        result:['库存数量排行'],
        innerList: ['库存数量排行', '商品库存类型统计(图)','商品库存类型统计(表)']}
    ]
}

我想在拿到index后更新这个位置的result,我发现直接写不生效,也不报错

onChange(event) {
    const key = event.currentTarget.dataset.key;
    
    this.setData({
      outList[key]['result'] :event.detail
    })
  },

 所有参考了下改成如下,生效了

onChange(event) {
   
    const key = event.currentTarget.dataset.key;
    const state = "outList["+key+"].result"
    this.setData({
      [state] :event.detail
    })
  },

 

你可能感兴趣的:(小程序)