Angular Firebase检索数据并将数据用于其他检索数据(实时)

Angular Firebase检索数据并将数据用于其他检索数据(实时),angular,firebase,firebase-realtime-database,ionic4,Angular,Firebase,Firebase Realtime Database,Ionic4,(据我所知,这不能实时完成。) 我已经处理这件事四天了,但我就是做不到。我需要你的帮助 这是我的数据库: 我想在html中显示所有通知,其中包含用户的名称和pp,它应该可以实时工作 我的代码正在工作,但没有按我想要的方式工作。据我所知,我想要的不适用于数组 notifications : Array<any>=[] this.userUid = firebase.auth().currentUser.uid this.db.database.ref("/user

(据我所知,这不能实时完成。)

我已经处理这件事四天了,但我就是做不到。我需要你的帮助

这是我的数据库:

我想在html中显示所有通知,其中包含用户的名称pp,它应该可以实时工作

我的代码正在工作,但没有按我想要的方式工作。据我所知,我想要的不适用于数组

notifications : Array<any>=[]
this.userUid = firebase.auth().currentUser.uid
      this.db.database.ref("/users/"+this.userUid+"/notifications/").on("value",snap=>{this.notifications=[],snap.forEach(a=>{
        
         var type = a.child("type").val()
         var userpath = this.db.database.ref("/users/"+a.child("who").val())
         if(type=="request"){
          var formId = a.child("formId").val()
        
           userpath.once("value",x=>{this.notifications.push({notKey:a.key,type:type,name:x.child("name").val(),pp:x.child("pp").val(),who:a.child("who").val(),formId:formId})})
         }
         else if(type=="response"){
       
          userpath.once("value",x=>{this.notifications.push({type:type,name:x.child("name").val(),pp:x.child("pp").val(),who:a.child("who").val(),result:a.child("result").val()})}) 
         }
        })
       })
通知:数组=[]
this.userUid=firebase.auth().currentUser.uid
this.db.database.ref(“/users/”+this.userUid+“/notifications/”)on(“value”,snap=>{this.notifications=[],snap.forEach(a=>{
var type=a.child(“type”).val()
var userpath=this.db.database.ref(“/users/”+a.child(“who”).val())
如果(类型=“请求”){
var formId=a.child(“formId”).val()
userpath.once(“value”,x=>{this.notifications.push({notKey:a.key,type:type,name:x.child(“name”).val(),pp:x.child(“pp”).val(),who:a.child(“who”).val(),formId:formId})
}
else if(类型=“响应”){
userpath.once(“value”,x=>{this.notifications.push({type:type,name:x.child(“name”).val(),pp:x.child(“pp”).val(),who:a.child(“who”).val(),result:a.child(“result”).val()})
}
})
})

请编辑问题,以显示未按预期方式运行的代码,并解释具体问题是什么。问题中包含了指向JSON树图片的链接。请将其替换为实际的JSON文本,您可以通过单击溢出菜单中的导出JSON链接轻松获得该文本(⠇) 当然。将JSON作为文本可以进行搜索,让我们可以轻松地使用它来测试您的实际数据,并在我们的答案中使用它,这通常是一件好事。@FrankvanPuffelen您想让我直接将JSON文件放进去吗?@DougStevenson实际上我放代码并不是为了不让您感到困惑。
notifications : Array<any>=[]
this.userUid = firebase.auth().currentUser.uid
      this.db.database.ref("/users/"+this.userUid+"/notifications/").on("value",snap=>{this.notifications=[],snap.forEach(a=>{
        
         var type = a.child("type").val()
         var userpath = this.db.database.ref("/users/"+a.child("who").val())
         if(type=="request"){
          var formId = a.child("formId").val()
        
           userpath.once("value",x=>{this.notifications.push({notKey:a.key,type:type,name:x.child("name").val(),pp:x.child("pp").val(),who:a.child("who").val(),formId:formId})})
         }
         else if(type=="response"){
       
          userpath.once("value",x=>{this.notifications.push({type:type,name:x.child("name").val(),pp:x.child("pp").val(),who:a.child("who").val(),result:a.child("result").val()})}) 
         }
        })
       })