- 为什么会出现Cannot read property 'concat' of undefined?
用云开发上传图片,其中一个项目运行正常,但另一个项目运用的时候报错Cannot read property 'concat' of undefined,为什么同一段代码在不同项目上会有不同结果?求大神帮忙看看,具体代码如下,js代码: uploadImgHandle: function () { wx.chooseImage({ count: 9, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: res => { // tempFilePath可以作为img标签的src属性显示图片 const tempFilePaths = res.tempFilePaths this.setData({ tempImg: tempFilePaths }) } }) }, submit: function () { const promiseArr = [] //只能一张张上传 遍历临时的图片数组 for (let i = 0; i < this.data.tempImg.length; i++) { let filePath = this.data.tempImg[i] let suffix = /\.[^\.]+$/.exec(filePath)[0]; // 正则表达式,获取文件扩展名 //在每次上传的时候,就往promiseArr里存一个promise,只有当所有的都返回结果时,才可以继续往下执行 promiseArr.push(new Promise((reslove, reject) => { wx.cloud.uploadFile({ cloudPath: new Date().getTime() + suffix, filePath: filePath, // 文件路径 }).then(res => { // get resource ID console.log(res.fileID) this.setData({ fileIDs: this.data.fileIDs.concat(res.fileID) }) reslove() }).catch(error => { console.log(error) }) })) } 一个项目运行成功,另一个项目运行报错
2020-03-18 - 为什么预览图片时开发工具调试和真机调试不一样?开发者工具调试正常,但真机调试为什么预览不了图片?
图片是来自云存储,具体代码如下 js: previewImg: function (e) { let that = this; let imgArr = [] for(var i=0;i<that.data.dataList.length;i++){ imgArr[i] = that.data.dataList[i].fileIDs[0] } console.log(e.currentTarget.dataset.src); console.log(imgArr); for(var index in imgArr){ wx.previewImage({ current:e.currentTarget.dataset.src, //当前图片地址 urls: imgArr, //所有要预览的图片的地址集合 数组形式 success(res){ console.log(res) } }) } wxml: <view wx:for='{{item.fileIDs}}' wx:key='index'> <image class='img' src='{{item}}' data-src='{{item}}' bindtap='previewImg'></image> </view>
2020-03-17 - 为什么调用云函数返回值无法赋给自己定义的空集合?
我调用云函数获取云数据库集合内容,但是返回值无法赋给我自己定义的数组,最后输出的数组还是空的,求大神帮忙看看,十分感谢。具体代码如下 let that = this let dataList = [] wx.cloud.callFunction({ name: 'getdata', data: { jiH: 'comments', }, success(res) { console.log('云函数获取数据成功', res.result.data) that.setData({ dataList:res.result.data }) console.log('dalist',dataList) }, fail(err) { console.log('获取失败', err) }, }) console值为: [图片]
2020-03-16 - 小程序云开发中,插入数据添加日期serverDate报错,这个是怎么回事?
[图片] 如图,小白一枚。。
2020-03-07