我正在尝试检查是否使用了 Firebase 文档中给出的示例中的用户名:
function go() {
var userId = prompt('Username?', 'Guest');
checkIfUserExists(userId);
}
var USERS_LOCATION = 'https://SampleChat.firebaseIO-demo.com/users';
function userExistsCallback(userId, exists) {
if (exists) {
alert('user ' + userId + ' exists!');
} else {
alert('user ' + userId + ' does not exist!');
}
}
// Tests to see if /users/<userId> has any data.
function checkIfUserExists(userId) {
var usersRef = new Firebase(USERS_LOCATION);
usersRef.child(userId).once('value', function(snapshot) {
var exists = (snapshot.val() !== null);
userExistsCallback(userId, exists);
});
}
但是我引用的数据位于我在引用时遇到问题的数据层中:
firebaseio.com/{userID}/primary/{username}
151 (用户ID) | |> 初级 | |> 用户名:用户名
我想检查用户 ID 子项下主树下的用户名字段......有什么建议吗?