I am trying to retrieve some data from Firebase using JavaScript, but I have a problem. I can't get the items of my child "Usuarios". This is how my database looks like
var rootRef = firebase.database().ref().child("Usuarios");
rootRef.on("child_added", snap => {
var name = snap.child("Nombre").val();
var email `enter code here`= snap.child("Apellido").val();
$("#table_body").append("<tr><td>" + name + "</td><td>" + email + "</td><td><button>Remove</button></td></tr>");
});
@hazelcodes说的话,看起来像这样
var rootRef = firebase.database().ref().child("netflixfirebase-568e8/Usuarios");
I´ve got a solution, I added the function "childSnapshot"to the "Snapchot" that I already had.I checked each element (that is an Object) and took the properties they contained.
The code here:
var ref = firebase.database().ref ().child("Usuarios/");
ref.on("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
var keystl = Object.keys(childData);
console.log(childData);
console.log(keystl);
for (var i = 0; i < keystl.length; i++)
{
var k = keystl[i];
var nombre = childData[k].Nombre;
var apellido = childData[k].Apellido;
console.log(nombre, apellido);
$("#table_body").append("<tr><td>" + nombre + "</td><td>" + apellido + "</td><td><button>Remove</button></td></tr>");
}
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.