访问firebase数据库中的数据 [英] Accessing data in firebase database
本文介绍了访问firebase数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我有一个使用firebase数据库的Web应用程序。我在如何访问包围
的时间上遇到了困难?
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?
这是我的代码:
function getDataFirebase() {
return new Promise(function(resolve, reject){
refReview.on("value", async function(snap){
var data=snap.val();
console.log("awdaw",data);
})
})
}
推荐答案
循环从firebase返回的快照以获取对象内的值。
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])
})
})
})
})
}
当我们不知道从firebase生成的时间戳作为子节点的值时,这种情况就会失败。
This case falls when we don't know the value of generated timestamps from firebase as child nodes.
这篇关于访问firebase数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文