我试图通过多种方式阅读和显示Firebase数据库中的数据,但无法使其正常工作。 我的firebase中有以下结构: Firebase database
这是整个js代码:
var config = {
apiKey: "thecharactersoftheapikey",
authDomain: "xyxyxyxyxyxyxy.firebaseapp.com",
databaseURL: "https://xxxxxxxxxxx.firebaseio.com",
projectId: "xyxyxyxyxy",
storageBucket: "xxxxxxxxxx.appspot.com",
messagingSenderId: "12345678"
};
firebase.initializeApp(config);
/*If user is logged or Not and get the user email to display*/
firebase.auth().onAuthStateChanged(function(user) {
var name, email, picture;
if (user) {
name = user.displayName;
uid = user.uid;
email = user.email;
//picture = user.photoURL;
//document.getElementById("user-image").src = picture;
document.getElementById("user-name").innerHTML = email;
}else {
document.getElementById("members-area").style.display="none";
}
});
/*To Log out */
function singOut(){
firebase.auth().signOut().then(function() {
// Sign-out successful.
location.href="http://localhost/xxx/index.html";
}).catch(function(error) {
// An error happened.
});
}
/*Retrieving data from the database*/
var usersRef = firebase.database().ref('users');
usersRef.on('value', function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var childData = childSnapshot.val();
console.log(childData);
});
});
console.log不显示任何内容。
注意:我已经尝试过使用" child_added"而不是"价值"它不起作用。
答案 0 :(得分:0)
问题是我的数据库上的规则不允许来自任何来源的读/写。