首页 > 解决方案 > 使用 nativescript-plugin-firebase 添加一个带有查询的事件监听器

问题描述

我正在使用 nativescript-plugin-firebase 和 firebase 实时数据库在我的应用程序中构建聊天。我只需要收听发送到用户帐户的消息。

是否可以将侦听器addChildEventListener与查询一起使用以便仅侦听特定消息(在这种情况下发送到特定消息user_id)?

我可以在应用程序中过滤消息,但这不起作用,因为消息量很大。

我知道 Firebase 可以做到这一点,但是,我使用的是 nativescript-plugin-firebase

firebase.addChildEventListener(this.onMessagesChanged, "/chats").then(
      function(listenerWrapper) {
        var path = listenerWrapper.path;
        var listeners = listenerWrapper.listeners; // an Array of listeners added
        // you can store the wrapper somewhere to later call 'removeEventListeners'
      }
    )

这个想法是只听与用户相关的 /chats 而不是全部。

谢谢!

标签: firebasefirebase-realtime-databasenativescriptnativescript-vue

解决方案


添加子集合是@Manoj 所述的答案


推荐阅读