我希望得到每个实例的/玩家..用钥匙。我该如何实现? 我找不到任何东西。 我的结构是这样的:
我正在获得其他值(日期,状态,时间)。
this.gamesRef = db.list('/games');
this.allGames = this.gamesRef.snapshotChanges().map(changes => {
return changes.map(c => ({ key: c.payload.key, ...c.payload.val()
}));
});
<div *ngFor="let game of allGames | async">
<span class="game-div-date">{{game.date}}</span>
<span class="game-div-clock">{{game.time}}</span>
</div>
(我正在使用Firebase和Angular2)
答案 0 :(得分:1)
试试这个
this.gamesRef = db.list('/games');
this.allGames = this.gamesRef.snapshotChanges().map(changes => {
return changes.map(c => {
const games;
games.key= c.payload.key;
games.satus = c.payload.val().status;
games.time = c.payload.val().time;
let players=[]
c.payload.val().players.forEach(player=>{
players.push(player);
})
games.players = players;
return games;
});
});
这将创建您可以使用的自定义数据
<div *ngFor="let game of allGames | async">
<span class="game-div-date">{{game.date}}</span>
<span class="game-div-clock">{{game.time}}</span>
<div *ngFor="let player of game.players">
<span>{{player | json}}</span>
</div>
</div>