Прямо сейчас этот раздел кода проходит неопределенно до if(customerWaiting >0)
.Это проблема асинхронности, которую я не могу понять.
Судя по другим темам, на которые я смотрел, это очень простой вопрос и вопрос новичка, я просто не могу заставить его работать.
Я проверял, можете ли вы найти его для меня
Редактировать 1:
цель кода - увидеть, есть ли клиенты в базе данных firewase "customerWaiting", если естьзатем отобразить модальный режим, если нет, то сказать, что нет клиентов, ожидающих
structure for database is
customerWaiting
-Automatically generated ID
-customer information
Вот код
var customerWaiting;
var employeeWaiting;
var ref = firebase.database().ref();
$("#connectNextUser").click(function() {
{
ref.child("customerWaiting").on("value", function(snapshot) {
var customerWaiting = snapshot.numChildren();
console.log("There are " + snapshot.numChildren() + " customers waiting");
});
ref.child("employeeWaiting").on("value", function(snapshot) {
var employeeWaiting = snapshot.numChildren();
console.log("There are " + snapshot.numChildren() + " employees waiting");
});
}
if (customerWaiting > 0) {
$("#myModal").modal();
console.log("connect");
} else {
console.log("There are " + customerWaiting + " employees waiting");
console.log("no connect");
}
});