[PouchDB更改仅在第二次单击后才会触发

问题描述 投票:0回答:1

我正在将PouchDB数据库与Ionic 4一起使用。我尝试构建一个变更侦听器。如果我创建一个新文档,我的列表应该知道并自动刷新。

我尝试过的

checkForChanges() {
  this.pdb.changes({
    since: 'now',
    live: true,
    include_docs: true,
  }).on('change', (change) => {
    console.log(change);
    if (change.doc) {
      return this.publishers;
    }
  })
}

我解雇了此代码,请提交表单以创建新文档。问题:第二次单击后console.log会触发。为什么呢?

也许是一个重要的信息:我正在从模态对话框中进行此操作。

我的提交功能

create(publisher) {
  return this.pdb.post(publisher).then(() => {
    this.checkForChanges();
  });
}

你有什么想法吗?

angular ionic-framework ionic4 pouchdb
1个回答
0
投票

db.changes应该在页面加载时初始化,而不是在用户单击提交按钮时初始化。

© www.soinside.com 2019 - 2024. All rights reserved.