问题
I have this structure of my Firebase Database
Each library can have several albums. How can I display the albums for each library?
the albumsPerLib:
first element is the library key, and underneath each library key, I store the albums keys, that belong to it.
But I'm not used to NoSQL and can't figure how to join the tables to display the albums for each library.
回答1:
so this works:
getAlbumsThatBelongToLib(libKey:string):Observable<Album[]>{
//get the keys for the lib albums
const albumsPerLib$ = this.db.list(`albumsPerLib/${libKey}`);
//map the returned list of keys
//and get their details from the albums node
return albumsPerLib$
.map((albumKeys) => albumKeys
.map( (albumKey) => {
return this.db.object(`albums/${albumKey.$key}`)
}))
.flatMap((res) => {
return Observable.combineLatest(res);
});
}
来源:https://stackoverflow.com/questions/40999531/how-to-join-two-nodes-with-angularfire2-and-firebase