對不起,我的錯誤我很新,發佈堆棧溢出。希望我提供了足夠的信息。理論上,我試圖按取消刪除行(取下該部分)並刪除相應的ID(-KiN ...)。如何刪除特定的帖子ID?
當我單擊表中第一條記錄上的取消時,它將刪除數據庫中的第一條記錄,但如果我單擊了最後一條記錄,它仍會刪除第一條記錄。所以總之我無法取消對應於表中取消按鈕的預約。
https://jsfiddle.net/1s1h67u1/
https://i.stack.imgur.com/Uy0uK.png
var resvbTabRef = firebase.database().ref("Reservation/user")
resvbTabRef.on('child_added', function(snapshot) {
var user = firebase.auth().currentUser;
var specialKey = snapshot.key;
var fullName = snapshot.val().Name;
var phnNum = snapshot.val().Phone_Number;
var ResvUID = snapshot.val().uid;
var ResvDate = snapshot.val().Reservation_Date;
var NumPeopl = snapshot.val().Number_of_Guests;
var ResvEmail = snapshot.val().Email;
var ResvInfo = fullName + phnNum + ResvDate + NumPeopl + ResvUID + ResvEmail
if (user.uid == ResvUID) {
var resvData = ('<tr><td ="' + specialKey + '">' + specialKey + '</td><td>' + fullName + '</td><td>' + user.email + '</td><td>' + phnNum + '</td><td>' + ResvDate + '</td><td>' + NumPeopl + '</td><td>' + '<button type="button" class="btn btn-default btn-sm" data-key=' + ResvInfo.key + ' id="cancelResv"><span class="glyphicon glyphicon-remove"></span> Cancel</button>' + '</td></tr>')
$("#userResvTable").append(resvData);
} else {
console.log("error");
}
$('#userResvTable').on('click', 'button[type="button"]', function(snapshot) {
$(this).closest('tr').remove();
var resvbTabRef = firebase.database().ref("Reservation/user/")
resvbTabRef.once("value")
.then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var key = childSnapshot.key;
var childData = childSnapshot.val();
var ref = firebase.database().ref("Reservation/user/" + key)
return ref.remove().then(function() {
console.log('OK, gone');
console.log(childData)
}).catch(function(e) {
console.log('OOPS, problem:' + e.message);
})
childSnapshot.ref.remove();
// console.log(resTab)
})
})
這是否適合您的工作請在評論中提及? –
好吧,我會試試看。 –
但是在預訂/用戶中沒有uid。預訂/用戶包含我推送預訂到數據庫的按鍵。 –