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

Posted 最初的样子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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]     (千万记住中间没有点“.”)

              

           

以上是关于wepy根据下标对数组中的某个对象的元素进行赋值的主要内容,如果未能解决你的问题,请参考以下文章