gpt4 book ai didi

Firebase child_added 仅添加子项

转载 作者:行者123 更新时间:2023-12-03 05:54:27 24 4
gpt4 key购买 nike

来自 Firebase API:

Child Added: This event will be triggered once for each initial child at this location, and it will be triggered again every time a new child is added.

一些代码:

listRef.on('child_added', function(childSnapshot, prevChildName) {
// do something with the child
});

但是由于此位置的每个子项都会调用该函数一次,有什么方法可以只获取实际添加的子项?

最佳答案

要跟踪自某个检查点以来添加的内容而不获取以前的记录,您可以使用 endAt()limit() 来获取最后一条记录:

// retrieve the last record from `ref`
ref.endAt().limitToLast(1).on('child_added', function(snapshot) {

// all records after the last continue to invoke this function
console.log(snapshot.name(), snapshot.val());

});

关于Firebase child_added 仅添加子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11788902/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com