Promise.all取不到页面DATA数据值或者方法?
发布于 5 年前 作者 xia39 6159 次浏览 来自 问答

var sctu[xh],html;

sss:function(){

    this.editorCtx.getContents({

      success(res) {

        html = res.html;

        var i=0

        var ss = res.html.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {

         url[i]=capture

         i++

        })

        console.log(url)

        var PromiseAllArr = [];//*********************用来存多个Promise

        for (var i = 0; i < url.length; i++) {

          console.log(i)

          PromiseAllArr.push(

            new Promise(function (resolve, reject) {

            let that = this;

            let xh=i;

            wx.cloud.uploadFile({

              cloudPath: "ssnew/" +rqzh.timeName(new Date()) +"-"+xh + ".jpg",

              filePath: url[xh],

              success(res) {

                console.log(html)

                html=html.replace(url[xh],res.fileID)

                sctu[xh] = res.fileID

                console.log(xh+"上传成功")

                // if (that.data.sctu.length==url.length){

                //   that.data.html = mm

                //   console.log(mm)

                //   that.data_updata()

                // }

                return resolve(res);

              }, fail(res) {

                return reject(i+"个上传失败");

                console.log(url[xh])

                console.log('上传图片失败', res)

              }

            })

           }))

           }

        Promise.all(PromiseAllArr).then(function (values) {

          let that=this;

          console.log(that.data.title)

        }).catch(reason => {

          console.log(reason)

          wx.cloud.deleteFile({

            fileList: sctu,

            success(res){

              console.log('删除已存文件')

            }

          })

        });

      }

    })

  }

TypeError: Cannot read property ‘data’ of undefined

    at ssnew.js? [sm]:181,我换成页面的函数,也提示找不到。

2 回复

可以了,谢谢

回到顶部