我有这样的数据库片段:
{
"users": {
"usersCount": {
"count": 61
...
...
}
}
}
我想为这样的变量赋值:
var count = getUserCount();
从这个函数:
function getUsersCount() {
const ref = db.ref('users/usersCount');
ref.once("value", function (snapshot) {
console.log("Value is: ", snapshot.val().count); // There value is right
return snapshot.val().count;
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}
但无论我尝试什么,该函数都会返回 undefinde 或对象承诺