为什么存入数组的顺序的是乱序的呀,是for循环出问题了吗?有大佬帮忙吗?
发布于 4 年前 作者 guiying82 885 次浏览 来自 问答

 review:function(){


    var username = (wx.getStorageSync('username')||[])

    wx.setStorageSync('username', username)

    wx.cloud.callFunction({

      name:"login",

      data:{

        id:username,

        action: "getdata",

      }

    }).then(res=>{

      for(var index in res.result.data[0].课程号){

        this.setData({

          Cid:res.result.data[0].课程号

        })

        wx.cloud.callFunction({

          name:"login",

          data:{

            cid:this.data.Cid[index],

            sid:username,

            action:"getGdata"

          }

        }).then(res=>{

          var grade = this.data.Grade

          grade.push(res.result.data[0].分数)

          var bgrade = this.data.Bgrade

          bgrade.push(res.result.data[0].补考分数)

          var cgrade = this.data.Cgrade

          cgrade.push(res.result.data[0].重修分数)

          var isB = this.data.IsB

          isB.push(res.result.data[0].是否已补考)

          var isC = this.data.IsC

          isC.push(res.result.data[0].是否已重修)

          this.setData({

            Grade:grade,

            Bgrade:bgrade,

            Cgrade:cgrade,

            IsB:isB,

            IsC:isC,

          })

        })


        wx.cloud.callFunction({

          name:"login",

          data:{

            id:this.data.Cid[index],

            action: "getCdata",

          }

        }).then(res=>{

          var cname = this.data.Cname

          cname.push(res.result.data[0].课程名)

          var bplace = this.data.Bplace

          bplace.push(res.result.data[0].补考地点)

          var btime = this.data.Btime

          btime.push(res.result.data[0].补考时间)

          var cplace = this.data.Cplace

          cplace.push(res.result.data[0].重修地点)

          var ctime = this.data.Ctime

          ctime.push(res.result.data[0].重修时间)

          this.setData({

            Cname:cname,

            Bplace:bplace,

            Btime:btime,

            Cplace:cplace,

            Ctime:ctime

          })

          console.log(res.result.data[0])

        })

    }

    })

  },

1 回复

for循环的顺序是从0开始,数组push是添加到最后一个。

回到顶部