javascript - 如何使用 AngularFire2 和 Firebase 连接两个节点?

标签 javascript angular firebase firebase-realtime-database angularfire2

我的 Firebase 数据库有这样的结构

enter image description here

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

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

但我不习惯 NoSQL,无法弄清楚如何连接来显示每个库的专辑。

最佳答案

所以这有效:

  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);
  });
}

关于javascript - 如何使用 AngularFire2 和 Firebase 连接两个节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40999531/

相关文章:

javascript - Jquery Popup 不居中

javascript - 错误 : unable to get local issuer certificate while running yarn command

javascript - 无法动态构造链接标签

android - 是否有可能阻止 Firebase 的 onDataChange() 最初被触发?

swift - 在 Swift 中将 Firebase 的一个子节点从一个节点更改为另一个节点

javascript - 按 2 个动态键对数组进行排序

html - angular2 : Supplied parameters do not match any signature of call target, 即使我有所有需要的参数

html - 在 Angular 6 中使用 HTML anchor 链接#id

javascript - Angular 异步调用与 react 和 Node 异步调用中的“this”引用

firebase - 是否可以重命名firebase数据库名称?