我试图来检查用户名用作在火力地堡文档中给出的示例:查找数据火力地堡
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下的主树下的用户名字段...任何建议?
嗨吉姆!我对你的结构有点困惑。如果我的用户ID是151,我的名字是“kato”,那么路径中的数据是'151/primary/kato/kato'?或者在你的例子中是{用户名}错误? – Kato 2013-02-16 15:26:34