检索父ID未知的孩子的数据-Firebase [英] Retrieve data of child of unknown parent ID - Firebase
本文介绍了检索父ID未知的孩子的数据-Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Firebase数据库,如图所示.
I have a Firebase database like shown in the image.
我希望所有数据以绿色突出显示.但是我不知道用红色突出显示的键.
I want to get all the data highlighted in GREEN. But I don't know keys highlighted in RED.
这应该是什么JavaScript代码?
What should be the JavaScript Code for this?
谢谢.
推荐答案
这将记录所有电话号码:
This would log all phone numbers:
var usersRef = firebase.database().ref("users");
usersRef.on("child_added", function(snapshot) {
console.log(snapshot.child("phoneno").val());
});
请注意,Firebase 文档和
Note that the Firebase documentation and Codelab cover this and a lot more. I highly recommend you spend some time on those, to become more familiar with Firebase.
如果您要一次打印所有电话号码,可以执行以下操作:
If you want to print all phone numbers once, you can do so with:
var usersRef = firebase.database().ref("users");
usersRef.once("value", function(snapshot) {
snapshot.forEach(function(userSnapshot) {
console.log(userSnapshot.child("phoneno").val());
});
});
这篇关于检索父ID未知的孩子的数据-Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文