user12711491
user12711491

Reputation: 1

How can I delete data from firebase thru web app?

Here's my JavaScript code.

var rootRef = firebase.database().ref().child('User');
rootRef.on("child_added", snap => {

  var description = snap.child("description").val();
  var title = snap.child("title").val();
  var article = snap.child("article").val();

  $("#table_body").append("<tr><td>" + title + "</td><td>" + description + "</td><td>" + article + "</td><td><button>Remove</td></tr>");
});

Upvotes: 0

Views: 348

Answers (1)

Kingsley Solomon
Kingsley Solomon

Reputation: 480

The simplest way to delete data is to call remove() on a reference to the location of that data. So in your case, you'd need to have a function to delete the data, passing in the child key then calling the function when the remove button is clicked.

function deleteData(dataKey) {
  firebase.database().ref('User/' + dataKey).remove()
}
var rootRef = firebase.database().ref().child('User');
rootRef.on("child_added", snap => {

  var description = snap.child("description").val();
  var title = snap.child("title").val();
  var article = snap.child("article").val();

  $("#table_body").append("<tr><td>" + title + "</td><td>" + description + "</td><td>" + article + "</td><td><button onclick='deleteData(" + snap.key()  + ")'>Remove</td></tr>");
});

Upvotes: 1

Related Questions