我正在将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();
});
}
你有什么想法吗?
db.changes应该在页面加载时初始化,而不是在用户单击提交按钮时初始化。