如何加入两个节点与AngularFire2和Firebase? [英] How to JOIN two nodes with AngularFire2 and Firebase?

查看:148
本文介绍了如何加入两个节点与AngularFire2和Firebase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



每个图书馆可以有几张专辑。如何显示每个图书馆的相册?



albumsPerLib:第一个元素是图书馆密钥,在下面每个库密钥,我存储相册密钥,属于它。



但我不习惯NoSQL,也不能计算如何加入表格显示每个图书馆的相册。

解决方案


  getAlbumsThatBelongToLib(libKey:string):Observable< Album []> {
//获取lib相册的键
const albumsPerLib $ = this.db.list(`albumsPerLib / $ {libKey}`);

//映射返回的键列表
//并从相册节点获取它们的详细信息
return albumsPerLib $
.map((albumKeys)=> albumKeys
.map((albumKey)=> {
return this.db.object(`albums / $ {albumKey。$ key}`)
)))
。 flatMap((res)=> {
return Observable.combineLatest(res);
});
}


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.

解决方案

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

这篇关于如何加入两个节点与AngularFire2和Firebase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆