Add a listener to a child inside of a firebase generated key?

前端 未结 1 1065
余生分开走
余生分开走 2020-12-21 11:28

Given the layout

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


        
相关标签:
1条回答
  • 2020-12-21 11:48

    Updating the answer based upon your comment.

    You want to listen to /activity/$theid/thread/$threadId:

    Rather than nesting, break out the /thread/$threadId into it's own location at the root.

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

    Now when a new thread is added you can just listen to /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()); 
    });
    
    0 讨论(0)
提交回复
热议问题