2017-01-25 184 views
1

'child_added'工作正常,但'child_removed'不起作用。Firebase'child_removed'事件侦听器不工作

数据索引是“.indexOn”:“status”。

  • 火力地堡数据

    { 
        "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" 
         } 
        } 
    } 
    
  • 火力地堡事件侦听器

    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目标是否存在问题?或者它是否与设置indexOn有关? (设置indexOn是必需的)

回答

1

你的意思是说child_moved事件没有被解雇吗?因为那是你正在听的。

如果孩子你有兴趣的去除,试着聆听child_removed代替child_moved

例:

notiRef.on('child_removed', function(snapshot) { 
     // probably will work. 
}); 
+0

这是我的错误。 思想被“移除”,但打字被“移动”。 谢谢。 – user7354286