多条云数据库更新promise.all写法
发布于 5 年前 作者 cyan 4992 次浏览 来自 问答

希望全部返回后再取消等待框,不知道怎么判断全部返回,百度了下,好像要用promise.all,不知道怎么写

//遍历数组,调用updata更新数据

 ergodicArr(){

   wx.showLoading({

     title: ‘修改中’,

   })

   this.data.obj.splice(0, this.data.obj.length) //清空数组

  //遍历queryResult数组,mun值改变过则将该项添加进obj数组

 for (var i = 0, len = this.data.queryResult.length;i<len;i++){

     if (this.data.queryResult[i].num!=0){

       this.data.obj.push(this.data.queryResult[i])

     }

   }

   //遍历obj数组,调用obj云函数

  for (var i = 0, len = this.data.obj.length;i<len;i++){

     this.updata(this.data.obj[i])

   }

  },


//传入的id为字符串,需要改成数值型

updata(e){

   wx.cloud.callFunction({

     name:‘changeData’,

     data:{

       id:e.id*1,

       obj:field,

       value:e.num

     }

   }).then(res=>{

       setTimeout(function () {

         wx.hideLoading()

   }).catch(err=>{

      setTimeout(function () {

         wx.hideLoading()

       })

   })

  },

3 回复

var promise3 = new Promise(function(resolve, reject) {

  setTimeout(resolve, 100, ‘foo’);

});

这里的setTimeout(resolve, 100, ‘foo’);可以是任意一个函数吗?怎么传参

回到顶部