javascript - Remove() 函数在 web 的 firebase 中不起作用
问题描述
这是.js文件。我试图做的是在单击 html 页面中的特定行时创建一个 onclick 删除功能。到目前为止,我可以获得子键(嵌套),但删除函数会以某种方式抛出错误,即 career-delete.html:1 Uncaught ReferenceError: MCu9V4ypS is not defined at HTMLButtonElement.onclick (career-delete.html:1)。
userImagesRef1.once("value", function(snapshot) {
var val1, val2, val3;
var ParentKey = snapshot.key;
console.log("PK"+ParentKey);
snapshot.forEach(function(childSnapshot) {
childSnapshot.forEach(function(snap){
var childKey = snap.key;
console.log("CK" + childKey);
var Vacancy = snap.child("VacancyNumber").val();
console.log("VacancyNumber" + Vacancy);
// var NoticeNumber = snap.child("Service").val();
// var NameofWork = snap.child("Title").val();
snap.child('pictures').forEach(function(openPicturesSnap){
console.log("KEY LINKS: " + openPicturesSnap.key);
// var i = 0;
if(openPicturesSnap.key == 0){
val1 = openPicturesSnap.val();
// console.log("LINKS1111::::" + val1 );
}
if(openPicturesSnap.key == 1){
val2 = openPicturesSnap.val();
}
if(openPicturesSnap.key == 3){
val1 = openPicturesSnap.val();
}
})
var Service = String(snap.child("Service").val());
// console.log(Service)
var ts = snap.child("timestamp").val();
// console.log("TS:" + ts);
var Title = String(snap.child("Title").val());
// console.log(Title)
let Numberofposts = String(snap.child("NumberofPosts").val());
// console.log(Numberofposts);
var SNo = "";
var State = snap.child("Status").val();
var IssueDate = snap.child("IssueDate").val();
var ClosingDate = snap.child("ClosingDate").val();
var Remarks = String(snap.child("Remarks").val());
$("#tableBody").append("<tr><td>"+ SNo +"</td><td><a href = '" + val1+ "'>" +Vacancy+"</a></td>"+ "<td><a href = '" +val2 + "'>" +Service+"</a></td><td>" + Title + "</td><td>"+Numberofposts+"</td><td>" + IssueDate + "</td><td>"+ClosingDate + "</td> <td>" + State+"<td><a href = '" +val3 + "'>" +Remarks+"</a>"+ "</td><td>"+'<button type="button" onClick=Delete('+childKey+'); class="btn delete">X</button>'+"</td></tr>" );
})
})
function Delete(key){
var feedRef = firebase.database().ref("user-images").child(key);
feedRef.remove()
.then(function(){
console.log("Remove succeeded.")
alert("Added");
// console.log(key.val());
})
.catch(function(error){
console.log("Remove Failed!"+error.message)
});
}
});
解决方案
您需要添加一些双引号,如下所示:
<button type="button" onclick="Delete('" +childKey+ "');" class="btn delete">X</button>
推荐阅读
- azure - Azure 上使用 htaccess 文件强制 https 的静态网站
- arrays - 将值分配给动态多维数组的第一维和第二维时,VBA 下标超出范围
- reactjs - 共同依赖
- ios - Facebook IOS sdk:不支持本机上的 FBSDKLoginBehavior
- c# - 如何一键检查带有垂直滚动条的CheckedListBox中的所有项目?
- twig - 是否可以通过 Shopware 6 管理中的两个单独插件将相同的树枝模板扩展两次?
- azure - Azure 专用终结点和 Terraform
- azure - Azure Databricks 的静态 IP
- c# - 如何测试原始sql实体框架
- java - BorderLayout 中的 GridBagLayout 问题:BorderLayout.CENTER 中没有显示