我要传递一个省ID provinceIds
数组,我想查询并返回每个Universities
中的所有Province
。到目前为止,我只从第一省返回大学。总共可以传递9个可能的ID(南非9个省)。我尝试进行迭代,最后以很多奇怪的代码结尾,“我不理解自己。”
如果您知道执行此操作的任何其他方法,我会开放的。
export class UniversitiesService {
private collection: AngularFirestoreCollection<University>;
universities: Observable<University[]>;
constructor(
private afs: AngularFirestore
) { }
getUniversitiesByProvince(provinceIds: string[]): Observable<University[]> {
this.collection = this.afs.collection('Universities',
ref => ref.where('provinceID', '==', provinceIds[0]));
this.universities = this.collection.snapshotChanges()
.map(actions => {
return actions.map(a => {
const data = a.payload.doc.data() as University;
data.Id = a.payload.doc.id;
return data;
});
});
return this.universities;
}
}