- uploadTask进度前台显示报错?
大神们帮我看看 这是咋回事呢[代码]postImages: [代码][代码]function[代码] [代码]() {[代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]that = [代码][代码]this[代码][代码] [代码][代码]var[代码] [代码]quantity = 9[代码][代码] [代码] [代码] [代码][代码]query.chooseImages(quantity, [代码][代码]function[代码][代码](imageRes){[代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]filePaths = imageRes.tempFilePaths [代码][代码] [代码] [代码] [代码][代码]for[代码] [代码]([代码][代码]var[代码] [代码]i = 0; i < filePaths.length; i++) {[代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]filePath = filePaths[i][代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]imagesPreviewTemp = {[代码][代码]'filePath'[代码][代码]:filePath,[代码][代码]'fileID'[代码][代码]:[代码][代码]''[代码][代码],[代码][代码]'progress'[代码][代码]:0}[代码] [代码] [代码][代码]that.data.imagesPreview.push(imagesPreviewTemp)[代码] [代码] [代码][代码]that.setData({[代码] [代码] [代码][代码]imagesPreview:that.data.imagesPreview[代码] [代码] [代码][代码]})[代码][代码] [代码] [代码] [代码][代码]var[代码] [代码]fileName = common.getUniqueFileName(app.globalData.userInfo._id)[代码] [代码] [代码][代码]var[代码] [代码]cloudPath = fileName + filePath.match(/\.[^.]+?$/)[0][代码][代码] [代码] [代码] [代码][代码]query.uploadImages(cloudPath, filePath, [代码][代码]function[代码][代码](res) {[代码] [代码] [代码][代码]//uploadFile成功后回调[代码] [代码] [代码][代码]var[代码] [代码]fileID = res.fileID[代码] [代码] [代码][代码]that.data.imagesPreview[i].fileID = fileID[代码][代码] [代码] [代码] [代码][代码]that.setData({[代码] [代码] [代码][代码]imagesPreview: that.data.imagesPreview[代码] [代码] [代码][代码]})[代码][代码] [代码] [代码] [代码][代码]}, [代码][代码]function[代码][代码](res) {[代码] [代码] [代码][代码]//uploadTask.onProgressUpdate成功后回调[代码][代码] [代码] [代码] [代码][代码]that.data.imagesPreview[i].progress = res.progress[代码][代码] [代码][代码]// 一直在这里报错,说that.data.imagesPreview[i].progress is not defined.[代码][代码] [代码] [代码] [代码][代码]that.setData({[代码] [代码] [代码][代码]imagesPreview: that.data.imagesPreview[代码] [代码] [代码][代码]})[代码][代码] [代码][代码]console.log([代码][代码]'上传进度'[代码][代码], res.progress)[代码][代码] [代码][代码]// console.log('已经上传的数据长度', res.totalBytesSent)[代码][代码] [代码][代码]// console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]// wx.hideLoading()[代码][代码] [代码] [代码] [代码][代码]})[代码][代码] [代码][代码]},[代码] 一直报错说that.data.imagesPreview[i].progress is not defined. 但是初始值已经有了个progress:0了,为什么会报错呢?
2019-11-03