2017-01-25 94 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