wepy根据下标对数组中的某个对象的元素进行赋值

1 //单选
2 select: function (e) {
3     let index = e.currentTarget.dataset.index;                
4     let staffList = this.staffList;
5     let newli = 'staffList[' + index + '].checked';
6     this[newli] = !this.staffList[index].checked;
7 }

上述代码取自    https://www.cnblogs.com/dreamstartplace/p/12202465.html   功能。

由于在小程序中赋值是   this.setData({    [newli] = !this.staffList[index].checked       })      这样的,由于项目的变动,需要将代码放在wepy框架中,而在wepy动态修改数据不用setData,直接赋值就可以了,但是一定要注意在这里是   this[newli]     而不是    this.[newli]     (千万记住中间没有点“.”)

              

           

猜你喜欢

转载自www.cnblogs.com/dreamstartplace/p/12753838.html