比如我现在有个data数据如下:

data: {
  playIndex: null,
  courseList: [{
    videoId: '0',
    isPlaying: false,
  }, {    
    videoId: '1',
    isPlaying: false,
  }]
},

 

我现在想要修改courseList里面的isPlaying的值该怎么做呢?

var thisIdx = e.currentTarget.dataset.index;
var playStatus = "courseList[" + thisIdx + "].isPlaying";
this.setData({
  [playStatus]:true 
});

 

里面的thisIdx表示你当前点击的是第几个。注意在拼接playStatus的时候需要有空格!!!然后用修改数据的时候用"[]"把上面的变量包起来,赋值即可。

相关文章:

  • 2021-12-18
  • 2022-01-30
  • 2022-02-06
  • 2022-02-09
  • 2022-02-09
  • 2021-10-28
  • 2021-05-24
猜你喜欢
  • 2022-01-25
  • 2022-01-18
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案