我正在使用Ionic 4的PouchDB数据库。我尝试构建一个更改监听器。如果我创建了一个新文档,我的列表应该知道这一点并自动刷新。
我尝试过的
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();
});
}
你有什么想法吗?
发布于 2020-01-18 18:04:30
db.changes应该在页面加载时初始化,而不是在用户单击submit按钮时初始化。
https://stackoverflow.com/questions/59799305
复制相似问题