如何同时从子节点和子节点中检索firebase数据库数据?

时间:2017-08-03 19:46:45

标签: javascript html firebase firebase-realtime-database firebase-authentication

我希望同时从Child和Child中的子项(即业务子项内的Business Child和Departments子项)在两个firebase数据库位置显示数据。所以我尝试在下面的代码中使用多个then语句,但它没有显示任何数据。我做错了什么?

     function searchcompany() {

       firebase.auth().onAuthStateChanged((user) => {
          if (user) {
          var IDtoSearch = document.getElementById('input-search').value;
          FindthisID.value = IDtoSearch;

          var userId = firebase.auth().currentUser.uid;
          var name = document.getElementById("header");
        return firebase.database().ref('/BusinessIDs/' + IDtoSearch).once('value').then(function(snapshot) {

               name.innerHTML = snapshot.val().BusinessName;

          // ...
        });

      }
    }).then(

       function showcompanydepts(data) {


              var container = document.getElementById('DepList'); 
              container.innerHTML = '';

        firebase.auth().onAuthStateChanged((user) => {
          if (user) {

        return firebase.database().ref('/BusinessIDs/' + IDtoSearch + '/Departments/').then(function(snapshot) {

              data.forEach(function(DepSnap) {
                var key = DepSnap.key;
                console.log(key);
                var Depts = DepSnap.val();
                var DeptCard = `

                <div class="button">
                        <button><span>Click Me</span></button>
                </div>
                `;

                container.innerHTML += DeptCard;
              })
          // ...
            });
          }
        })
      })
  }

0 个答案:

没有答案