“child_added”工作正常,但“child_removed”不起作用。
数据索引为“.indexOn”:“status”。
Firebase 数据
{ "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 事件监听器
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. });
上面代码中的所有三个“child_removed”都不起作用。 是不是设置ref target有问题?还是indexOn设置有问题? (需要设置indexOn)
最佳答案
您的意思是 child_moved 事件不会被触发吗?因为这就是你正在听的。
如果是删除您感兴趣的子项,请尝试监听child_removed 而不是child_moved。
例如:
notiRef.on('child_removed', function(snapshot) {
// probably will work.
});
关于javascript - Firebase 'child_removed' 事件监听器不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41855414/