美文网首页
递归遍历数组循环发送请求

递归遍历数组循环发送请求

作者: 我背井离乡了好多年 | 来源:发表于2020-11-05 11:19 被阅读0次
// 遍历发过来的id,请求经纬度
// 再传一个回调函数,拿到所有请求结果后要做什么事
// times传0,表示从第一个id开始请求
getConnectInfo(idList, times, func) {
  return new Promise((resolve, reject) => {
    this.$apollo.query({
      query: require('_graphql/train/query/findAllByExamDesignIdAndDeviceId.gql'),
      variables: {examDesignId: this.currentExamDesignId, deviceId: idList[times]},
      fetchPolicy: 'no-cache'
    }).then((data) => {
      let obj = data.data.findAllByExamDesignIdAndDeviceId
      this.connectResultArr.push(obj)
      times = times + 1
      if (times > idList.length - 1) {
        // 不知道为什么不能resolve出去
        // resolve("888")
        let arr = JSON.parse(JSON.stringify(this.connectResultArr))
        // 调用制作飞线的函数
        func(arr)
        return
      }
      this.getConnectInfo(idList, times, func)
    })
  })
},

相关文章

网友评论

      本文标题:递归遍历数组循环发送请求

      本文链接:https://www.haomeiwen.com/subject/ktctbktx.html