我可以以某种方式确定ref
与-1
之间是否存在val newTotal
之间没有儿童吗?
这是我希望能够发挥作用的。如果查询中存在子项,则运行回调。
ref.orderByValue().startAt(-1).endAt(newTotal).limitToLast(1).once("child_added", function(snap){
/* Runs only when query yields a result */
if (snap.exists()){
...
} else {
...
}
});
newTotal
为0或任何正整数。
答案 0 :(得分:3)
child_
事件只会在相关子项存在/更改时触发。
要检测何时没有孩子,您需要(也)听取value
事件:
var query = ref.orderByValue().startAt(-1).endAt(newTotal).limitToLast(1)
query.once("value", function(snapshot){
if (snapshot.exists()){
snapshot.forEach(function(child) {
..
});
} else {
console.log('No child exists');
}
});