html52.com
我爱小程序-开发者交流社区

wx.cloud.database().watch()数据改变时回调失败?

有问题的代码:

db.collection('test')
  .where({
    createTime: null,
  })
  .watch({
    onChange: (res) => {
      console.log(res)
    },
    onError: (err) => {
      console.log(err)
},})


修改后的代码(无问题):

db.collection('test')
  .where({
    createTime: false,
  })
  .watch({
    onChange: (res) => {
      console.log(res)
    },
    onError: (err) => {
      console.log(err)
},})


当查询条件中包含null的情况下,监听方法watch只会初始化init一次,后续collection的增删改都不会引起onChange;当将条件改为{ createTime: false }时,则不会出现watch失败的问题。

网友回复

xplee:

不是带了where条件嘛,说明没有符合条件的数据要监听,也就不会回调onChange

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付