Removing listener on removed nodes

时间:2016-08-31 17:41:14

标签: node.js firebase

I have a simple scenario where i have attached listener on dynamic path in Firebase.

a
.. b
..... c (dynamic multiple nodes)
..... c1
......c2 
ref.child(a).child(b).child(c).on('child_changed',onChildChange);

I am removing some c nodes as per some conditions, so do i need to listener from it or will it be automatically removed.

2 个答案:

答案 0 :(得分:1)

Just the opposite of the .on:

ref.child(a).child(b).child(c).off('child_changed',onChildChange);

https://www.firebase.com/docs/web/api/query/off.html

答案 1 :(得分:1)

You have to call remove on a reference to remove data.

firebase.database().ref('a/b/c').remove();

child events are used to monitor data in the list, you can use these events to know when data has been added, modified or removed.

In your case, you should use child_removed, note that using this event has nothing to do with data removal. Whenever you work with lists, it is recommended that you use all 3 child events in conjunction.

firebase.database().ref('a/b/c').on('child_removed', function(data) {
  //Data has been deleted, do something here!
});