2017-05-25 16 views
0

我在firebase中擁有以下db結構。我想在我的視圖中使用ngFor檢索這個集合和顯示。但是我想要讀取每個對象的Key(當我們使用push方法時產生的firebase)以後使用它。如何從firebase db集合準備鍵和值

enter image description here

我檢索這樣的數據。

this.dbref = firebase.database().ref('My top node here'); 
this.dbref.once('value').then(snapshot => this.myProperty = snapshot.val()); 

如果我登錄myProperty的,我可以看到對象集合,像這樣鑰匙一起,但我不知道的方式來讀取與每個對象相關的關鍵。有人可以幫忙嗎?

enter image description here

回答

2

我認爲你正在尋找:

this.dbref = firebase.database().ref('My top node here'); 
this.dbref.once('value').then(snapshot => { 
    this.myProperty = snapshot.val(); 
    snapshot.forEach(child => { 
    console.log(child.key, child.val()); 
    }); 
}) 
+0

非常感謝!有效!! – Prabi