![](/img/trans.png)
[英]How would I cycle through all child nodes in Firebase and read all data nodes inside them in Javascript?
[英]How do I iterate through all child nodes in firebase database using javascript?
下面是我的 firebase 數據庫的結構。 我想遍歷居民節點下的所有名為 details 的節點,並顯示存儲在名稱下的值,例如“first_name”。 協助將不勝感激。
{
"nibebe-530edaddclose":{
"Estate":{
"WVLN5yN88oZSzgIl7JpfbiRadYq1":{
"details":{},
"residents":{
"details":{
"-LsxA0DMx5EqUe6xSvvM":{
"block_number":,
"email":,
"first_name":,
"house_number":,
"last_name":,
"password":,
"phone_number":,
}
}
}
}
"XxWh0j0QYIUZ35chQqkemwnB3Mw1":{
"details":{},
"residents":{
"details":{
"-LsuDQO699osHfqq5BIC":{
"block_number":,
"email":,
"first_name":,
"house_number":,
"last_name":,
"password":,
"phone_number":,
}
}
}
}
}
}
}`
提前致謝
你的意思是,在這個例子中,你想獲得兩個first_name
字段的值? 不幸的是,這沒有任何技巧,也沒有好的方法。 Firebase 不支持查詢,並且(根據我的經驗)不太適合這種用例。 您需要獲取這些對象的第一個共享祖先(在本例中為Estate
)的ref
( https://firebase.google.com/docs/reference/js/firebase.database.Reference )並手動遍歷它們. 根據數據的大小,這可能是一個冗長的操作,因此您可能需要考慮批處理等,以防止此操作阻塞其他操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.