javascript - 向 firebase 生成的 key 内的子项添加监听器?

标签 javascript json firebase

鉴于布局

+ activity
  + -K5p_pBXog4kb0SVLXxj
    text:'something',
    when:111
    + thread
      + -K5paF53zm3cuudP9FUQ 
        id:8,
        text:'something else'

有没有办法向诸如/activity/*/thread 之类的事件内的任何新“线程”插入添加监听器?

当添加新事件时,我正在获取有关这些事件的提要,但是当附加线程时,不会触发任何内容。我是否需要将 [thread] 部分移出它自己的根并将线程 ID 与事件 ID 进行匹配,以了解何时针对主事件线程进行了线程注释?

最佳答案

根据您的评论更新答案。

你想听/activity/$theid/thread/$threadId :

而不是嵌套,打破 /thread/$threadId进入它自己的根位置。

{
  "threadActivity": {
     "$activityId": {
        "$threadId" : {

        } 
     }
   } 
}

现在,当添加新线程时,您只需收听 /threadActivity/$activityId :
var ref = new Firebase('https://<my>.firebaseio.com/threadActivity');
var activityRef = ref.child('some-id');
activityRef.on('child_added', function(snap) {
  // will update you for every child at the location and each child added
  console.log(snap.val()); 
});

关于javascript - 向 firebase 生成的 key 内的子项添加监听器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377741/

相关文章:

javascript - Web 开发在图像之上显示图像

javascript - 如何设置容器 div 的宽度和高度?

json - 创建新的 Realm 列表并添加项目

android - 无法解析依赖 firebase 和 google play 服务

reactjs - react : Disconnecting firebase ref on componentWillUnMount

javascript - 来自react-bootstrap的ListGroupItem和Button在同一行

javascript - 如何在不重新链接的情况下将 jQuery 包含在 iframe 中?

javascript - 数数没有。 json 对象中的条目数在多个键中具有特定值

javascript - JSON 带有空数值? (非0)

swift - 访问不可用 此资源仅适用于注册开发人员计划的开发人员