云函数删除时报错?
发布于 4 年前 作者 guiyingyu 2144 次浏览 来自 问答
JS页面

deleteImage: function (e) {
    var that = this;
    var images = that.data.images;
    var index = e.currentTarget.dataset.index;//获取当前长按图片下标
    wx.showModal({
      title: '提示',
      content: '确定要删除此图片吗?',
      success: function (res) {
        if (res.confirm) {
          var id = that.data.routers[e.currentTarget.dataset.indexs]._id;
          images.splice(index, 1);
          //云函数删除
        wx.cloud.callFunction({
          name: 'pictureDeletion',
          data:{
            _id:id,
          },
          success: res => {
            console.log(id)
            wx.showToast({
              title: '[云函数] [pictureDeletion] 删除成功!!',
            })
            console.log('[云函数] [pictureDeletion] 删除成功!! ', res)
            wx.hideLoading();
          },
          fail: err => {
            wx.showToast({
              title: '[云函数] [pictureDeletion] 调用失败' + err,
            })
            console.error('[云函数] [pictureDeletion] 调用失败', err)
          }
        })
        } else if (res.cancel) {
          console.log('点击取消了');
          return false;
        }
        that.setData({
          routers: images
        });
      }
    })
  },
云函数页面

报错原因:

thirdScriptError

Cannot read property ‘4’ of undefined;at api showModal success callback function

TypeError: Cannot read property ‘4’ of undefined

初步判断是这里出错了,具体原因也不清楚呀

1 回复

你的报错应该不是云函数引起的把?

应该是没有that.data.routers[4]

而且下面这个是不是有问题?

'id’是什么鬼?是不是该把 ‘’ 去掉

回到顶部