我希望同时从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;
})
// ...
});
}
})
})
}