编程语言
首页 > 编程语言> > 写小程序自定义方法时,this.setData无法正常赋值

写小程序自定义方法时,this.setData无法正常赋值

作者:互联网

setCountDown: function () {
        var thisPage = this
        let Pause = thisPage.data.isPause
        if (Pause == false) {
            //刷新时间以及递减时间范围
            let time = 1000;
            let wPause = thisPage.data.wasPause
            let test = thisPage.data.pingData[0].time
            var Text = thisPage.data.showText
            let {
                listData
            } = thisPage.data;
            // map里   v为当前数组操作的元素,i为当前元素在数组的坐标

            let list = listData.map((v, i) => {
                if (v.time < 0) {
                   v.time = 0;
                }

                let formatTime = thisPage.getFormat(v.time);

                v.time -= time;

                if (test <= 0) {                    
                   thisPage.setData({
                        test: 0,
                        Text : "交换攻防",
                        Pause : true,                        
                    })
                    console.log(Text)
                    thisPage.showPopup()
                }
                v.countDown = `${formatTime.mm}:${formatTime.ss}`;
                console.log("经过暂停前" + wPause)
                if (wPause == true) {
                    v.time = v.time + 1000;
                    thisPage.setData({
                        wasPause: false
                    })
                    console.log("first time to regoing!")
                    console.log("经过暂停后" + wPause)
                }

                console.log(test)
                console.log(thisPage.data.pingData[0])

                return v;
            })
            thisPage.setData({
                listData: list
            });
            //setTimeout里  在第二个函数指定毫秒时后触发第一个函数的方法
            //现在语句意思为 =》在time=1000毫秒时,执行setCountDown方法,实则为循环
            setTimeout(thisPage.setCountDown, time);
        }
        if (Pause == true) {
            return
        }

原js数组中均有相关的data元素接受读取数据,但使用setData后依然无法将值传入data中

 

标签:Pause,自定义,let,数组,time,setData,data,thisPage,赋值
来源: https://www.cnblogs.com/UniqueBurning7/p/16115446.html