我正在尝试等待每个循环的firebase完成,一旦完成,我想检查在我的父div
中填充了多少个div。如果length == 0
,则表示firebase查询的结果为空,并且未添加任何内容。
但是,无论是否0
结果附加到div
或许多内容,每次都会触发条件。看起来.then实际上并没有等待我的每个循环完成并注入html。它立即运行,这就是为什么if条件总是被击中。请帮忙......
firebase.database().ref('zones').once('value', (snapper) => {
snapper.forEach((snap) => {
//for each data point in firebase, inject it into the html
})
}).then(() => {
//once the loop is done and the html has been populated, do a check to see if any divs were created with the queried data
//if divs length is 0, that means the result came back empty
if($("#parent > div").length == 0) { console.log("no results") }
});