【问题标题】:How to JOIN two nodes with AngularFire2 and Firebase?如何使用 AngularFire2 和 Firebase 加入两个节点?
【发布时间】:2018-09-14 22:53:24
【问题描述】:

我的 Firebase 数据库具有这种结构

每个库可以有多个专辑。如何显示每个库的专辑?

albumsPerLib: 第一个元素是库密钥,在每个库密钥下面,我存储属于它的专辑密钥。

但我不习惯 NoSQL,不知道如何加入 以显示每个库的专辑。

【问题讨论】:

标签: javascript angular firebase firebase-realtime-database angularfire2


【解决方案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);
  });
}

【讨论】:

    猜你喜欢
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    相关资源
    最近更新 更多