2017-01-25 4 views
1

'child_added'は正常に動作しますが、 'child_removed'は機能しません。Firebase '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" 
         } 
        } 
    } 
    
  • 3は、上記のコードで 'child_removed' すべてが動作しません

    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. 
    }); 
    

Firebaseイベントリスナ。 refターゲットを設定するのは問題ですか?または、indexOnを設定することに問題がありますか? (indexOnを設定する必要があります)

答えて

1

child_movedイベントは発生しませんか?それがあなたが聞いているものですから。それはあなたが興味を持っている子どもたちの除去がある場合

、代わりにchild_movedのchild_removed のために聞いてみてください。

例:

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

それは私のミスです。 思考は「削除」されましたが、入力は「移動」されました。 ありがとうございます。 – user7354286

関連する問題