亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

等到在 Firebase 數據庫(網絡)中檢測到新數據

等到在 Firebase 數據庫(網絡)中檢測到新數據

慕無忌1623718 2022-05-26 14:15:46
在此示例中,我想在 firebase 數據庫的父節點中創建一個名為“friend”的新節點時更改站點。我不知道如何讓它等到它檢測到新節點。    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貢獻1862條經驗 獲得超7個贊

您不需要循環,但您確實需要將更改位置的代碼移動到偵聽器中:


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";

  }

})

如果您只想檢查節點是否存在,可以簡化為:


firebase.database().ref('users/' + uid).child('friend').on('value', function(snapshot){

  if (snapshot.exists()) {

    window.document.location = "whatever.html";

  }

})


查看完整回答
反對 回復 2022-05-26
  • 1 回答
  • 0 關注
  • 109 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號