Firebase事件在开始返回所有值时触发

时间:2017-05-26 13:38:55

标签: javascript node.js firebase firebase-realtime-database

将firebase用于小型消息传递应用。使用.on("child_added")函数也可以正常工作。

问题是当应用程序运行时,此函数会触发所有以前的子项,然后停止。

为什么会出现这种情况?我们如何阻止它?

2 个答案:

答案 0 :(得分:0)

需要使用child_updated代替child_added

答案 1 :(得分:0)

使用旗帜。

第一次在对象中设置字段 例如:

let read_ts = (new Date()).getTime();

my_ref.on("child_added", snap => {
    if ( !snap.val().read_ts ){
        console.log("is new")
    } else {
        console.log("is old")
    }
});