簡體   English   中英

如果數據不存在,Firebase查詢不會顯示任何數據

[英]Firebase query dont display any data if data dont exist

如果數據不存在,Firebase查詢將不顯示任何數據no null no undefined,什么也沒有消息,僅顯示是否在數據庫中找到了東西。

  const ref =  this.fb.database().ref("Users");
     var self = this;

      ref.orderByChild('cellphone').equalTo('+351' + this.phoneNumber.toString()).on("child_added", (snapshot) => {
      console.log(snapshot.val().cellphone);

        if (snapshot.exists()){
          let toast = self.toastCtrl.create({
            message: 'Cellphone already exist',
            duration: 2000,
            position: 'bottom'
          });

          toast.present();
        }

        if(!snapshot.exists()){ // it dont even get here 
          console.log('can register');
        }

    });

我的數據庫結構,因此,如果找不到它,我的手機也不會一發不可收拾

我的數據庫

解決方案是using "value" instead of "child_added"

對於查詢的節點下的每個匹配子節點,將觸發child_added事件。 如果沒有匹配的子代,它將不會觸發。

這意味着要測試節點是否存在,必須使用value處理程序。 並且由於查詢可以有多個結果,因此您將需要遍歷子級。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM