2016-12-06 93 views
0

我有我的火力地堡數據庫的這種結構如何使用AngularFire2和Firebase加入兩個節點?

enter image description here

每個圖書館能有幾張專輯。我如何顯示每個圖書館的相冊?

albumsPerLib:第一個元素是庫密鑰,並且在每個庫密鑰的下面存儲屬於它的專輯密鑰。

但我不習慣NoSQL,也不知道如何加入來顯示每個庫的相冊。

+0

見http://stackoverflow.com/questions/30299972/joining-data-between-paths-based-on-id-using-angularfire –

+0

是angularjs不是2 ,而且angularfire1不是2.我還沒有處理。我認爲但不確定那些舊的沒有使用可觀察的? – Ron

+0

啊,那確實不同。我想你必須使用'map()'調用,但是我自己只用於同步操作。 –

回答

1

所以此工程:

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); 
    }); 
} 
相關問題