【发布时间】:2018-04-19 22:35:39
【问题描述】:
我正在尝试查询一个空的 firebase 列表。问题是可观察方法 subscribe 永远不会完成,我无法向用户显示 ddbb 列表为空。
函数 getUserAppointmentsByDate(...) 正在调用 getUserAppointments(...),其中 this.database.list('/appointment/users/' + user_uid) 是 空的 输入用户 (user_uid) 的 firebase 列表。
我应该如何管理对 firebase 的空查询?
提前致谢!
getUserAppointmentsByDate(user_uid: string, start: string, end: string) {
if (typeof (user_uid) == "undefined" || typeof (start) == "undefined" || typeof (end) == "undefined") {
console.error("invalid argument for getPatientReport");
return;
}
return this.getUserAppointments(user_uid)
.map(
(appointment) => {
return appointment
.filter((appointment) => {
var appointmentStart = new Date(appointment.start);
var startFilter = new Date(start);
var endFilter = new Date(end);
//Filter old, not cancelled and not deleted
return (appointmentStart.getTime() < endFilter.getTime())
&& (appointmentStart.getTime() > startFilter.getTime())
&& (appointment.status != AppointmentStatus.CANCELLED);
});
})
}
getUserAppointments(user_uid: string): any {
return this.database.list('/appointment/users/' + user_uid) //*THIS IS AN EMPTY LIST
.mergeMap((appointments) => {
return Observable.forkJoin(appointments.map(
(appointment) => this.database.object('/appointment/list/' + appointment.$key)
.take(1)))
})
}
【问题讨论】:
标签: firebase ionic-framework observable angularfire2