欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序 wx.uploadFile在安卓手機(jī)上面the same task is working問(wèn)題解決

 更新時(shí)間:2016年12月14日 09:57:37   投稿:lqh  
這篇文章主要介紹了微信小程序 wx.uploadFile在安卓手機(jī)上面the same task is working問(wèn)題解決的相關(guān)資料,需要的朋友可以參考下

微信小程序 wx.uploadFile在安卓手機(jī)上面the same task is working問(wèn)題解決

微信小程序上傳圖片的時(shí)候,如果是多圖片上傳,一般都是直接用一個(gè)循環(huán)進(jìn)行wx.uploadFile

這個(gè)在電腦上面測(cè)試與蘋(píng)果手機(jī)上面都不會(huì)有什么問(wèn)題

但當(dāng)用安卓測(cè)試的時(shí)候,你會(huì)發(fā)現(xiàn)小程序會(huì)提示一個(gè)the same task is working

wx.uploadFile不能并行,因?yàn)閣x.uploadFile是一個(gè)異步函數(shù),所以循環(huán)的時(shí)候在安卓手機(jī)上會(huì)出現(xiàn)并行

解決的方法

做一個(gè)上傳完的標(biāo)識(shí),然后

用遞歸算法進(jìn)行上傳

在上傳成功的回調(diào)函數(shù)里面,直接遞歸,標(biāo)識(shí)滿足直接跳出,完成所有圖片上傳

貼上個(gè)代碼段

//上傳標(biāo)識(shí)
var i=0
//imglist為要上傳圖片的路徑數(shù)組
uploadImg: function () {  
  var that = this
  if (i == imglist.length) {
  //清空還原
   news = ""
   city = ""
    i=0
   wait = true
   imglist = []
   serverImg = []
   retrunList = []
   that.setData({
    loding: false,
    src: [],
    disabled: false
   })
   return;
  }
   var imgcount = imglist.length;
   wx.uploadFile({
    url: config.serverUrl('index.php/user/uploadtu'),
    filePath: imglist[i],
    name: 'file',
    formData: { 'user': 'test' },
    success: function (res) {
     serverImg.push(res.data)
     if (imgcount == serverImg.length) {
      var serverImgStr = serverImg.join("|")
      wx.request({
       url: config.serverUrl('index.php/user/baobeiadd'),
       method: 'POST',
       data: Util.json2Form({
        imglist: serverImgStr,
        userId: userId,
        news: news,
        city: city,
        latitude: latitude,
        longitude: longitude
       }),
       header: {
        'content-type': 'application/x-www-form-urlencoded'
       },
       success: function (res2) {
        if (res2.data.state == "ok") {
 
         that.setData({
          loding: false,
          butTxt: "發(fā)布",
          disabled: false
         })
          
         Util.mesUrl("發(fā)布成功!", "../index/index")
        }
        else {
         Util.mes("描述至少10人字以上哦,還有圖片也要選哦!")
        }
       }
      })
     }else
     {
     //這里直接遞歸
     i++;
     that.uploadImg();
     }
    },
    fail: function (e) {
     console.log(e)
     Util.mes("圖片上傳失敗,請(qǐng)重新發(fā)布!" + i)
    }
   })
 
 },

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論