我有一个对象,该对象的属性为ID列表。
const obj = { list: ['id-1', 'id-2', 'id-3'] };
当前,这就是我所能做的。但是它返回一个Observables数组。
// Class variable...
records: Observable<Record>[];
constructor(private afDB: AngularFireDatabase) {}
getRecords () {
this.records = obj.list.map(id => this.afDB.object(`path/to/collection/${id}`));
}
与this.records
数组不同,将Observable
作为Observable
的数组似乎不是最适合在模板中使用的。
我宁愿拥有records: Observable<Record[]>
而不是records: Observable<Record>[]
。
反正是否有将这些ID作为查询函数的一部分传递给angularfire数据库的原因?
答案 0 :(得分:0)
您可以执行以下操作:
afDB.collection('yourCollection', ref => ref.where('id', '==', 'yourId'));
在https://github.com/angular/angularfire2/blob/master/docs/firestore/querying-collections.md上找到了这个