I've been trying to achieve the following, but I couldn't
If I wanted to alert ada's first name, what code should i use?
I used this, it returns undefined:
if (user) {
// User is signed in.
alert('user signed')
// Get a reference to the database service
var database = firebase.database();
var query = firebase.database().ref("users");
query.once("value")
.then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
// key will be "ada" the first time and "alan" the second time
var key = childSnapshot.key.val;
// childData will be the actual contents of the child
var childData = childSnapshot.val();
alert(key);
});
but it didn't work, any suggestions?
note: completely new to JavaScript
in the docs , it is
// key will be "ada" the first time and "alan" the second time
var key = childSnapshot.key;
not var key = childSnapshot.key.val;
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.