Remove Child Firebase

Asked

Viewed 346 times

0

Hello, I’m starting to study Firebase and I’m putting together a simple Timeline, but I stopped in time to try to delete a particular post. I’ve seen people say it’s done by remove(), but I don’t know how to apply the code. Thanks for your help. https://jsfiddle.net/p3781j0w/3/

1 answer

0

In your delete, you call ref.remove(), but ref was never declared...

To remove a Child, you need to indicate what your key is. I suggest you create a function that will receive the key to be removed and then remove it:

function deletePost(postKey){
    feed.child(postKey).remove();
}

And in your onChildAdded you pass the key per parameter to this function:

    '<a class="pull-right feed-menu" id="deletePost" onclick="deletePost('+snapshot.key+')">'+

Browser other questions tagged

You are not signed in. Login or sign up in order to post.