【发布时间】:2018-04-24 16:42:14
【问题描述】:
有没有比这更好的方法来查询 Firebase RTDB 中的特定数据集?我能想到的就是使用 forEach() 并在每个发出的 observable 上推送到订阅内的 BehaviorSubject。让我知道!我已经被困了一段时间了。
hits = new BehaviorSubject([]);
territories = ['16830', '16832', '16838'] // Zip Codes
getTerritories(territories) {
territories.forEach(key => {
this.db.object(`locations/${key}`).snapshotChanges()
.map(zip => zip.payload.val())
.subscribe(zip => {
let currentHits = this.hits.getValue();
currentHits.push(zip);
this.hits.next(currentHits);
});
});
}
this.hits.subscribe(res => console.log(res));
【问题讨论】:
标签: angular firebase firebase-realtime-database rxjs behaviorsubject