1
我无法使用以下结构(部分)从我的Firebase数据库中检索密钥。无法检索Firebase数据的密钥
{
"Belmonte" :
{
"p1" : "p1",
"p2" : "p2",
"p3" : "p3",
"p4" : "p4"
},
"Bricktown" :
{
"p1" : "p1",
"p2" : "p2",
"p3" : "p3",
"p4" : "p4"
},
"Divino Rostro" :
{
"p1" : "p1",
"p2" : "p2",
"p3" : "p3",
"p4" : "p4"
},
"Esperanza" :
{
"p1" : "p1",
"p2" : "p2",
"p3" : "p3",
"p4" : "p4"
}}
这里是我用来检索数据的代码(来自样本)。我收到了警报,看看代码是否进入循环,但没有。
firebase.initializeApp(config);
var hello = document.getElementById("hello");
var dbref = firebase.database().ref().child("roomlist");
//dbref.on("value", snap => hello.innerText = snap.val());
dbref.once("value", function(snapshot) {
// The callback function will get called twice, once for "fred" and once for "barney"
hello.innerText = snapshot.numChildren();
var ctr = 0;
snapshot.forEach(function(childSnapshot) {
// key will be "fred" the first time and "barney" the second time
var key = childSnapshot.key();
var val = childSnapshot.val();
ctr++;
alert(ctr);
// childData will be the actual contents of the child
hello.innerText = ctr;
});
});
而且
hello.innerText = snapshot.numChildren();
回报20.这是数据库中的数据的实际数量。
这是我们从2.x SDK向3.x版本所做的更改之一。很高兴听到您发现它。 –