firebase - 使用 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 而不是全部。
谢谢!
解决方案
添加子集合是@Manoj 所述的答案
推荐阅读
- swift - 如何初始化可选数组?
- python - Tkinter 按钮搞砸了一切
- c++ - 不正确的模板专业化
- c++ - 尝试使用 init() 启动我的程序,但它告诉我没有合适的默认构造函数可用
- inno-setup - 有没有办法防止使用 SignTool 删除签名?
- javascript - 如何组合两个具有相同父对象的嵌套父对象javascript数组?
- swift - Swift继承函数返回类型不能是子类型
- spring - spring-boot 对 context-path/ 的请求为静态内容生成 405 Method Not Allowed 错误
- javascript - 仅当javascript中的输入字符串未提供时如何应用默认时区?
- ios - 为什么将preferredLayoutAttributesFitting 和systemLayoutSizeFitting 与自定尺寸集合视图单元一起使用