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 버전으로 변경 한 사항 중 하나입니다. 네가 발견했다고 들었어. –