我想访问firebase数据库中的特定节点。
我实际上是以:
运行我的组件中的代码如下所示:
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”?
答案 0 :(得分:0)
game.rounds[roundId].startedAt
答案 1 :(得分:0)
组件:
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,
}
}