我試圖來檢查用戶名用作在火力地堡文檔中給出的示例:查找數據火力地堡
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