您好,我正在为我的应用构建一个小型仪表板。我对 Firebase 有点陌生,但它为我节省了很多时间。所以我想做的是从数据库中直接检索到网络仪表板或将来任何其他相关数据的注册用户总数。所以我没有做一个小的登录表单,我可以登录。也许有人有任何类似的经历我在图片中添加了我的数据库结构。
// Initialize Firebase
var config = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
storageBucket: "...",
messagingSenderId: "..."
};
firebase.initializeApp(config);
// Firebase Variables
var auth = firebase.auth();
// on state changed
auth.onAuthStateChanged(firebaseUser => {
// check email
if(firebaseUser){
currentEmail.innerHTML = auth.currentUser.email
currentEmail.style.display = 'block';
singoutButton.style.display = 'block';
//singupForm.style.display = 'none';
signin.style.display = 'none';
signinEmail.style.display = 'none';
signinPassword.style.display = 'none';
signintext.style.display = 'none';
welcometext.style.display = 'block';
window.location = 'index.html';
} else{
signintext.style.display = 'block';
welcometext.style.display = 'none';
signin.style.display = 'block';
signinEmail.style.display = 'block';
signinPassword.style.display = 'block';
singoutButton.style.display = 'none';
//singupForm.style.display = 'block';
currentEmail.style.display = 'none';
}
});
最佳答案
要检索用户数,请尝试以下操作:
var ref = firebase.database().ref("users");
ref.once("value").then(function(snapshot) {
var numberOfChildren = snapshot.numChildren();
});
假设 users
是根节点的直接子节点。
numChildren()
returns numberReturns the number of child properties of this DataSnapshot.
更多信息在这里:
https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#numChildren
关于javascript - Firebase 检索用户号到网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49855270/