收藏
回答

云数据库存储时,不报错也存不进去,这是什么原因?

代码如下,请大佬帮我瞅瞅。数据传入的都没问题,不知道为什么就是存不进去。找了很久了也没个头绪。

formSubmit: function (e) {
    var time = util.formatDate(new Date()); //文件送达的时间
    var formObject = e.detail.value;
    var documentType='工程函件'//文件类别
    var isCheck=formObject.isCheck;//是否为原件
    var drafter=formObject.drafter;//起草人
    var theme = formObject.theme; //文件主题
    var pages = formObject.pages; //文件页数
    var remark = formObject.remark; //备注
    var state = '1'; //文件的状态(1.未确认 2.已确认)
    var confirmTime = ''; //文件的确认时间,新增时候默认空。剩余属性为送检人和联系电话通过查询user_idc来获得
    if (theme == null || theme == '' || theme.length == 0) {
      wx.showToast({
        title: '函件主题不能为空',
        icon: 'none'
      })
    } else if (drafter == null || drafter == '' || drafter.length == 0) {
      wx.showToast({
        title: '起草人不能为空',
        icon: 'none'
      })
    }else if (pages == null || pages == '' || pages.length == 0) {
      wx.showToast({
        title: '文件页数不能为空',
        icon: 'none'
      })
    } else {
      console.log("存储数据")
      wx.getUserInfo({
        success: function (data) {
          var nickName = data.userInfo.nickName;
          console.log(nickName)
          const db = wx.cloud.database();
          const appointment = db.collection('user_idc');
          db.collection('user_idc').where({
            nickName: nickName
          }).get({
            success: function (res) {
              var name = res.data[0].name;
              var tel = res.data[0].tel;
              var dep = res.data[0].persondepartment
              console.log(name, tel, dep, documentType, dep, isCheck, theme, drafter, pages, remark, confirmTime, time)
              const appointment = db.collection('projectDocument');
              db.collection('projectDocument').add({
                data: {
                  documentType: documentType,
                  department: dep,
                  isCheck: isCheck,
                  theme: theme,
                  drafter: drafter,
                  pages: pages,
                  remark: remark,
                  confirmTime: confirmTime,
                  state: '1',
                  name: name,
                  tel: tel,
                  sendTime: time
                },
                success: function (res) {
                  wx.showToast({
                    title: '递交成功',
                    icon: 'success'
                  });
                  wx.reLaunch({
                    url: '/pages/index/index',
                  })
                },
                fail:console.log(err)
              })
            }
          })
        }
      })
    }
  },


回答关注问题邀请回答
收藏

1 个回答

  • _人世间
    _人世间
    2019-12-14

    const appointment = db.collection('projectDocument');

                  db.collection('projectDocument').add({

    这两句是不是上一句没用了,要是你下边这样写。。还有你的db 在哪定义了?我没看到

    2019-12-14
    赞同
    回复 5
    • marquis
      marquis
      2019-12-14
      db的定义在上面const db = wx.cloud.database();
      2019-12-14
      回复
    • marquis
      marquis
      2019-12-14
      还是存不进去
      2019-12-14
      回复
    • _人世间
      _人世间
      2019-12-14回复marquis
      2019-12-14
      回复
    • _人世间
      _人世间
      2019-12-14回复marquis
      这两句话去掉,然后你断点输出,看看是走到哪一步不走了
      2019-12-14
      回复
    • marquis
      marquis
      2019-12-14
      解决了,虽然不知道哪里错了,但是我把没走那个地方的代码重写了。应该是某个属性名字打错了,谢谢大佬。
      2019-12-14
      回复
登录 后发表内容
问题标签