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.
What should be the JavaScript Code for this?
Thanks in advance.
答案 0 :(得分:1)
这会记录所有电话号码:
var usersRef = firebase.database().ref("users");
usersRef.on("child_added", function(snapshot) {
console.log(snapshot.child("phoneno").val());
});
请注意,Firebase documentation和Codelab涵盖了此内容以及更多内容。我强烈建议您花一些时间在这些上,以便更熟悉Firebase。
如果您想打印所有电话号码一次,可以使用以下方式打印:
var usersRef = firebase.database().ref("users");
usersRef.once("value", function(snapshot) {
snapshot.forEach(function(userSnapshot) {
console.log(userSnapshot.child("phoneno").val());
});
});
listening for value events on a collection of data的文档中介绍了这一具体案例。