收藏
回答

Promise.all取不到页面DATA数据值或者方法?

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 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-02-29

    2020-02-29
    有用 2
    回复
  • hbzyliyong
    hbzyliyong
    2020-02-29

    可以了,谢谢

    2020-02-29
    有用
    回复
登录 后发表内容
问题标签