Accessing data in firebase database

2019-07-27 23:12发布

So basically,I have a web application that uses firebase database. and I am having a hard time on how to access the encircled ones?

here is my code:

 function getDataFirebase() {
    return new Promise(function(resolve, reject){
        refReview.on("value", async function(snap){
            var data=snap.val();

            console.log("awdaw",data);

        })
    })
 }

enter image description here

1条回答
Ridiculous、
2楼-- · 2019-07-27 23:48

Loop over snapshot returned from firebase to get values inside the object.

function getDataFirebase() {
    return new Promise(function(resolve, reject){
        refReview.on("value", async function(snap){
            let rootkey = snap.key
            console.log(rootkey)
            snap.forEach(snapshot => {
                let childKey = snapshot.key
                console.log(childKey)
                Object.keys(snapshot.val()).map(k => {
                  console.log(snapshot.val()[k])
                })
            })
        })
    })
}

This case falls when we don't know the value of generated timestamps from firebase as child nodes.

查看更多
登录 后发表回答