![](/img/trans.png)
[英]Listen to child_changed (Firebase Realtime Database) on web
[英]When using onValue to listen to a Firebase realtime database for updates, is it possible to retrieve the event type of child_added or child_changed?
我正在使用以下內容查詢 Firebase 實時數據庫以獲取 React 應用程序中的更新:
onValue(query(ref(db, 'users')), (snapshot) => {
if(snapshot.exists()) {
// do stuff with snapshot.val()
}
}, (cancelCallback) => {
console.log(cancelCallback);
});
正如預期的那樣,這將在實例化時返回users
節點下存在的所有數據,並在每次更改、添加或刪除該節點上的數據時再次執行。
是否可以從快照中檢索child_added
、 child_changed
或child_removed
的事件類型?
我查看了 Firebase 的文檔,但找不到解決方案。
是否可以從快照中檢索 child_added、child_changed 或 child_removed 的事件類型?
onValue()
不可能,但您可以分別使用onChildAdded()
、 onChildChanged()
和onChildRemoved()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.