问题描述
我有一个待办事项列表,每当添加或完成待办事项时我都需要更新。 UI 在没有我的主题的情况下完美更新,但是当我想使用一个主题时(当数据库更改时它会获得一个新值),它不会更新。
//Initial loading of all the todos
this.todos = await this.todoService.getTodos(this.locationId);
//Reloading todos whenever the database has changed.
//This subscription causes the UI to not refresh after deleting a todo or adding a new one.
this.subscription = this.dbService.subject.subscribe(async () => {
console.log('changes todo');
this.todos = await this.todoService.getTodos(this.locationId);
this.cd.markForCheck();
});
}
ionViewWillLeave() {
this.subscription.unsubscribe();
}
getTodos()
async getTodos(
locationId: string,limit?: number,done?: boolean
): Promise<any> {
let selector = {};
if (done !== false) {
selector = {
Type: 'remark',IsTodo: true,Shop: locationId,};
}
if (done == false) {
selector = {
Type: 'remark',Done_date: false,};
}
selector['Delivery_date'] = {
$exists: true,};
const options = {
selector,fields: [
'Title','Delivery_date','_id','_rev','IsPriority','ResponsibleUser','Comment','Done_date','Shop','Shop_name',],limit,// sort: [{ Type: 'desc' },{ Delivery_date: 'desc' }],};
const result = await this.dbService.find(options);
return result.docs;
}
编辑:添加了 getTodos()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)