【问题标题】:Angularfire2 list query limitToLastAngularfire2列表查询limitToLast
【发布时间】:2018-07-21 12:17:23
【问题描述】:

我想访问我的 firebase 数据库中的特定节点。

我实际上运行的是:

  • “angularfire2”:“^5.0.0-rc.4”,
  • “火力基地”:“^4.9.0”,

我的组件中的代码如下所示:

  this.id = this.route.snapshot.paramMap.get('id'); 
  auth.appUser$.subscribe(appUser => this.appUser = appUser );  

  if (this.id) 
  {
      //Live game state info          
      this.subscription = this.gameService.getLive(this.id).subscribe(action => {
        this.game = action.payload.val(); 
        console.log(this.game);
      });
    }
}

我在 gameService 中调用的函数如下所示:

 getLive(gameId) 
  {
    return this.db.object('/games/live/' + gameId).snapshotChanges();
  }

问题是我不知道如何在回合中访问节点“StartedAt”。但是我可以从我的实际“游戏”中看到所有完整的节点:

如何从特定回合访问“startedAt”?

【问题讨论】:

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


    【解决方案1】:

    组件:

          this.subscription = this.gameService
          .getLive(this.id)
          .subscribe(action => {
            this.game = {key: action.key, value: action.payload.val()};
            this.game.value.playerList = Object.values(this.game.value.playerList);
    

    this.game.value.rounds = Object.values(this.game.value.rounds);

            console.log(this.game.value.rounds[this.game.value.rounds.length-1]);
          });
        }
    

    游戏模型:

    import { Round } from './round';
    import { Player } from './player';
    
    export interface Game {
     key: string,
     value:{
     state: string, 
     playerList: Player[], 
     rounds: Round[], 
     startedAt: string,
     roundCounter: string,
           }
    }
    

    【讨论】:

      【解决方案2】:

      game.rounds[roundId].startedAt

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-28
        • 1970-01-01
        • 1970-01-01
        • 2016-12-02
        相关资源
        最近更新 更多