【问题标题】:Firebase & Angular: get the tournament with less than 16 subscribersFirebase 和 Angular:订阅人数少于 16 人的锦标赛
【发布时间】:2017-12-10 23:51:32
【问题描述】:

我是 Firebase 的新手,目前正在开发一个网站。我想访问我的 Firebase 数据库,更具体地说是带有“淘汰赛”小节的比赛部分。在本小节中,我想查找并返回具有属性“编号”且值小于 16 的锦标赛。如果有,那么我想为该锦标赛添加一个新订阅者。如果没有,我想在 knockout 部分添加一个新的锦标赛。

我现在只有以下代码,位于我的 tours.service 文件中。我连接到 db 的 knockout 部分,但我不知道如何返回属性 number 低于 16 的锦标赛。

(下面我还加了数据库结构截图)

@Injectable()
export class TournamentsService {

  constructor(private db: AngularFireDatabase) {

  }

  getOrCreateTournament(type){
    // type is 'knockout' in this case (like in the database section, see picture)
    let tournamentWithLessThan16 = this.db.list('/tournaments/' + type );

  }
}

【问题讨论】:

    标签: javascript angular firebase firebase-realtime-database


    【解决方案1】:

    你应该订阅你的函数:

    @Injectable()
    export class TournamentsService {
    
      constructor(private db: AngularFireDatabase) {
    
      }
    
      getOrCreateTournament(type){
        // type is 'knockout' in this case (like in the database section, see 
      picture)
         let tournamentWithLessThan16 = this.db.list('/tournaments/' + type).map(items => items.map(item => item));
         tournamentWithLessThan16.subscribe(items => console.log(items));
      }
     }
    

    【讨论】:

      猜你喜欢
      • 2019-08-02
      • 2016-09-27
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 2012-12-02
      • 2013-06-16
      • 1970-01-01
      相关资源
      最近更新 更多