Help me with my code I'm trying to delete data from firebase but I'm getting reference error
Anshuman Tiwari
Posted on November 19, 2022
function showNotes(){
let html = "";
let notesElm = document.getElementById('notes');
get(child(dbRef,"Notes")).then((snapshot) => {
var count = 0
if (snapshot.exists()) {
const noteData = snapshot.val()
for (const item in noteData) {
if (Object.hasOwnProperty.call(noteData, item)) {
const element = noteData[item];
html+=`
<div class="card mx-2 my-2 noteCard" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">${element.title}</h5>
<p class="card-text">${element.text}</p>
<button id=${count} onclick="deleteElement(${element.title})" class="btn btn-primary">Delete Node</button>
</div>
</div>
`;
}
count++
}
notesElm.innerHTML = html;
} else {
console.log("No data available");
}
}).catch((error) => {
console.error(error);
});
}
function deleteElement(item){
remove(ref(db,"Notes/"+item))
.then(()=>{
console.log("Data has been removed")
})
.catch((err)=>{
console.log(err);
})
window.location.reload()
}
💖 💪 🙅 🚩
Anshuman Tiwari
Posted on November 19, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
react Building a Firebase-Powered React Application: A Comprehensive Guide for Developers
November 18, 2024
webdev Building a Dynamic News Page for Gladiators Battle: Key Features and Implementation
November 14, 2024