2017-05-25 9 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

関連する問題