如何使用AngularFire将firebase数据库值检索到列表中

如何使用AngularFire将firebase数据库值检索到列表中,firebase,firebase-realtime-database,ionic3,angularfire2,angularfire,Firebase,Firebase Realtime Database,Ionic3,Angularfire2,Angularfire,以下是我的firebase数据库的结构: 我试图检索姓名列表,但只通过单击按钮通过电子邮件发送 到目前为止,我掌握的代码是: toemail(){ this.db.list('profiles').snapshotChanges().subscribe( res => { res.forEach(doc => { this.people.push(doc.payload.val()); }); }); console.log(this.p

以下是我的firebase数据库的结构:

我试图检索姓名列表,但只通过单击按钮通过电子邮件发送

到目前为止,我掌握的代码是:

  toemail(){
this.db.list('profiles').snapshotChanges().subscribe(
  res => {
    res.forEach(doc => {
      this.people.push(doc.payload.val());
    });
  });
  console.log(this.people);
}
此代码将所有数据(电子邮件、游戏、姓名)添加到人员列表中。我怎样才能修改它,只将game=1的玩家的名字添加到玩家列表中


谢谢

我建议您使用start by为数据创建一个模型,因为这将真正有助于保持代码的干净性和可读性,并利用linting 下面是一些修改过的代码,可能会有所帮助

          toemail() {
            this.db.list('profiles').snapshotChanges().subscribe(
              res => {
                this.people = []; //Reset the array every time data changes
                this.people = res.filter(doc => {
                  let person = doc.payload.val() as Person; 
//Person is the data model. Although you can omit this part if you wish and the code will still work
                  return person.game === 1;
                });
              });
            console.log(this.people);
           }
Filter函数将一个数组作为输入,并在循环通过每个实体后返回一个新数组,并且仅当该实体满足某个条件时才将其添加到新数组中 在您的情况下,如果
person.game==1
则添加实体