javascript - Firebase 实时数据库 : Does 'value' event fires automatically

标签 javascript firebase-realtime-database dom-events

据我了解,当下面这行代码由 Javascript 解释/执行时

ref.on('值',回调)

(类似于document.addEventListener('click',callback))。回调被附加到该事件的 el/object,这样当该事件执行时,附加的回调(事件处理程序)就会被触发。

但是我观察到,当此 ref 处有一些数据时,当上面的代码行由 Javascript 解释/执行时,即使没有这样的触发器,firebase 'value' 事件也会自动触发作为该引用发生的添加/删除/修改操作。

此解释/假设是否正确,或者 value 事件的工作方式与添加/删除/修改操作触发的任何其他事件一样。在这种情况下触发因素是什么

此外,如果 value 事件自动触发,它实际上是否对该引用上的 Firebase 数据库进行异步/网络调用,然后获取该数据(快照)< em>or 是在客户端缓存的引用数据,即没有异步/网络请求。

有哪位 friend 可以澄清一下这个困惑吗?感谢您的帮助。

最佳答案

根据documentation :

You can use the value event to read a static snapshot of the contents at a given path, as they existed at the time of the event. This method is triggered once when the listener is attached and again every time the data, including children, changes. The event callback is passed a snapshot containing all data at that location, including child data. If there is no data, the snapshot will return false when you call exists() and null when you call val() on it.

当您附加监听器时,SDK 将使用其与数据库的持久连接来检查是否有新数据。如果没有新数据,则提供本地缓存的数据。

关于javascript - Firebase 实时数据库 : Does 'value' event fires automatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56413242/

相关文章:

javascript:检查元素是否可以接受一个值

javascript - Firebase push().key 长度总是 20 个字符吗?

node.js - Firebase云功能-Reference.update失败

javascript - 在不止一次添加允许的文件总数时,在更改事件监听器中对文件数组进行切片 - JavaScript

javascript - chrome 中未委托(delegate) click 事件

javascript - 嵌套循环中匿名闭包的可读性

javascript - 需要一些帮助来改进正则表达式

javascript - 附加的事件处理程序 'meta-data' 存储在哪里?在 "DOM,"对象上,或者...?

javascript - js - match() 未正确返回值

javascript - 检索嵌套对象 JavaScript