Reputation: 25
'child_added' works fine, but 'child_removed' does not work.
The data index is ".indexOn": "status".
Firebase data
{
"user uid" : {
"-Kb8FSBMOvcposJ-iJYL" : {
"createDate" : 1485140252291,
"message" : "login",
"response" : "none",
"status" : "0",
"title" : "8. sign-in"
},
"-KbL6d1xrfqCBAcP7_Qu" : {
"createDate" : 1485356045006,
"message" : "logout",
"response" : "none",
"status" : "1",
"title" : "sign-out"
}
}
}
Firebase event listener
var notiRef = firebase.database().ref('message/' + user.uid);
notiRef.orderByChild('status').equalTo('wait').on('child_added', function(snapshot) {
//do something...
});
notiRef.orderByChild('status').equalTo('wait').on('child_moved', function(snapshot) {
// not worked.
});
firebase.database().ref('notification/' + user.uid + '/uid').on('child_moved', function(snapshot) {
// not worked.
});
notiRef.on('child_moved', function(snapshot) {
// not worked.
});
All three 'child_removed' in the above code will not work. Is it a problem to set the ref target? Or is it a problem with setting indexOn? (Setting indexOn is required)
Upvotes: 1
Views: 746
Reputation: 141
Do you mean that child_moved events are not fired? Because that is what you are listening for.
If it is removal of children you are interested, try listening for child_removed instead of child_moved.
Ex:
notiRef.on('child_removed', function(snapshot) {
// probably will work.
});
Upvotes: 1