【问题标题】:Firebase 'child_removed' event listener not workingFirebase 'child_removed' 事件监听器不起作用
【发布时间】:2017-01-25 15:29:31
【问题描述】:

'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 目标有问题吗?还是设置 indexOn 有问题? (需要设置 indexOn)

【问题讨论】:

    标签: javascript firebase firebase-realtime-database


    【解决方案1】:

    您的意思是 child_moved 事件不会被触发吗?因为那是你在听的。

    如果是删除您感兴趣的孩子,请尝试收听 child_removed 而不是 child_moved

    例如:

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

    【讨论】:

    • 这是我的错。思想被“移走”,但打字被“移走”。谢谢。
    猜你喜欢
    • 2015-06-06
    • 2020-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多