循环浏览firebase数据



嗨,我正在尝试使用云函数访问firebase实时数据库中的嵌套数据,我的数据看起来像:

{
"RANGE1": {
"left": 2,
"overlayImage": "",
"right": 1,
"submittedInfo": {
"left_1": {
"TimeStamp": "2020-02-16 19:05:35",
"horozontalAccuracy": 10,
"latitude": 0000,
"longitude": 0000
},
"left_2": {
"TimeStamp": "2020-02-16 19:23:59",
"horozontalAccuracy": 10,
"latitude": 0000,
"longitude": 0000
},
"left_3": {
"TimeStamp": "2020-02-20 19:35:28",
"horozontalAccuracy": 10,
"latitude": 0000,
"longitude": 0000
},
"right_1": {
"TimeStamp": "2020-02-16 19:08:30",
"horozontalAccuracy": 10,
"latitude": 0000,
"longitude": 0000
}
}
},
"RANGE2": {
"left": 1,
"overlayImage": "",
"right": 1,
"submittedInfo": {
"left_1": {
"TimeStamp": "2020-02-12 22:07:11",
"horozontalAccuracy": 5,
"latitude": 0000,
"longitude": 0000
},
"right_1": {
"TimeStamp": "2020-02-12 22:36:36",
"horozontalAccuracy": 11.721012922544011,
"latitude": 0000,
"longitude": 0000
}
}
}
}

我有一个函数,它应该过滤并压平这些数据。但我似乎不知道如何深入节点。我所做的一切似乎都被访问[object object]或typeof((卡住了,当它应该是JSON对象时,它会返回一个字符串,仍然是

admin.database().ref(".../range").once('value').then((snapshot) => {
var flagInfo = [];
snapshot.forEach((range) => {
console.log("range is : " + range) // [object Object]
console.log("range[submitted] " + range['submittedInfo']) // undefined???
// what I need to do is something like: 
range["submittedInfo"].forEach((flagData) => { 
console.log(flagData.key)
console.log(flagData["latitude"]) // and so on for the rest of the keys
}) // end 
})

请查看此引用。每个部分都有一个很好的例子。

您应该使用方法child()val()。我现在手头没有测试场地,但应该是range.val()来获得范围,range.child('submittedInfo').val()来获得"submittedInfo"数据,但你必须弄清楚如何准确地做到这一点。如果你不设法让我知道,我会尽力在我这边实施它。

我希望它会有所帮助!

相关内容

  • 没有找到相关文章

最新更新