慕無忌1623718
2022-05-26 14:15:46
在此示例中,我想在 firebase 數(shù)據(jù)庫的父節(jié)點(diǎn)中創(chuàng)建一個(gè)名為“friend”的新節(jié)點(diǎn)時(shí)更改站點(diǎn)。我不知道如何讓它等到它檢測到新節(jié)點(diǎn)。 var friendUid; firebase.database().ref('users/' + uid).child('friend').on('value', function(snapshot){ friendUid = snapshot.val(); }) while(!friendUid){ //I've also tried with "friendUid == null" firebase.database().ref('users/' + uid).child('friend').on('value', function(snapshot){ friendUid = snapshot.val(); }) } window.document.location = "whatever.html";
1 回答

牧羊人nacy
TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
您不需要循環(huán),但您確實(shí)需要將更改位置的代碼移動到偵聽器中:
firebase.database().ref('users/' + uid).child('friend').on('value', function(snapshot){
var friendUid = snapshot.val();
if (friendUid == "what you're looking for") {
window.document.location = "whatever.html";
}
})
如果您只想檢查節(jié)點(diǎn)是否存在,可以簡化為:
firebase.database().ref('users/' + uid).child('friend').on('value', function(snapshot){
if (snapshot.exists()) {
window.document.location = "whatever.html";
}
})
添加回答
舉報(bào)
0/150
提交
取消