极客飞人 2019-07-29 16:06 采纳率: 0%
浏览 200

大佬们帮我看看this.data.imagesID执行了不同的条件分支有被赋予不同的值?

最近在开发个微信小程序,想通过wx.chooseImages,wx.cloud.uploadFile来获取图文件id,但是出现了很诡异的bug

先贴上自己写的代码

Page{
    data:{
        imagesID:[]
    }
    // 添加图片
    addimages: function (e) {
    var that = this
    var img = that.data.imagesUrl
    if(img.length<6){     
      var addtion = e.target.dataset.addimg
      if (addtion == undefined || addtion == 0) {
        wx.chooseImage({
          count:6,
          success: function (res) {          
            var tempFilePaths = res.tempFilePaths
            img = img.concat(tempFilePaths)
            for (var count = 0; count < that.data.imagesUrl.length;) {
              that.uploadImg(count)
              count++
            }
            that.setData({ imagesUrl: this.data.imagesID})        
          }
        })
      }
    }
    else {
      wx.showModal({
        title: '提示',
        content: '您上传的图片数量已达到上限',
      })
    }
  },
    // 上传图片文件
    uploadImg(count) {
    let that = this
    wx.cloud.uploadFile({
      cloudPath: (new Date()).valueOf()+'.png',
      filePath: this.data.imagesUrl[count],
    }).then(res=>{
      that.data.imagesID.push(res.fileID)
    })
  },

    // 提交表单
     submitForm(e) {
        let that = this
        for (var count = 0; count < that.data.imagesUrl.length;) {
      that.uploadImg(count)
      count++
    }
    console.log(that.data.imagesID)
     }
       if (res.requestType === "") {
        wx.showToast({
        title: '请选择需求类型',
        image: 'close-circle.png'
      })
    }
        else if (res.description == "") {
        wx.showToast({
        title: '请说明具体情况',
        image: 'close-circle.png'
      })
    }
        else {
            if (res.requestType == '知识') {
            school.add({
            data: {
              type: res.requestType,
              description: res.description,
              imagesUrl:that.data.imagesID,
            }
        }
}

代码大概就这样,同样在submitForm函数里都要执行先循环执行uploadImg()在不执行if、else if 直接else和执行if、else if 再else输出的那个that.data.imagesID的值前者shu'chu为默认的空数组,后者就正常被赋值了(还一定要console.log才行),大佬们帮我看看这究竟是什么问题…………,if else if只是调用了wx.showToast api,不会影响that.data.imagesID的输出

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog