How to delete/remove nodes on Firebase

后端 未结 6 1419
悲&欢浪女
悲&欢浪女 2020-12-07 22:27

I\'m using Firebase for a web app. It\'s written in plain Javascript using no external libraries.

I can \"push\" and retrieve data with \'.on(\"child_added\")\', but

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 23:04

    Firebase.remove() like probably most Firebase methods is asynchronous, thus you have to listen to events to know when something happened:

    parent = ref.parent()
    parent.on('child_removed', function (snapshot) {
        // removed!
    })
    ref.remove()
    

    According to Firebase docs it should work even if you lose network connection. If you want to know when the change has been actually synchronized with Firebase servers, you can pass a callback function to Firebase.remove method:

    ref.remove(function (error) {
        if (!error) {
            // removed!
        }
    }
    

提交回复
热议问题