node.js-Sweet Alert2 - 确认删除 (NodeJS/Express/Mongoose/MongoDB)
目前在我的 NodeJS 应用程序中,我有一个删除记录的内联确认:
<form id="btn-form" action="/thought/<%- thought._id %>?_method=DELETE" method="POST" onclick="return confirm('Are you sure you wish to delete this thought post?');">
<button class="btn-none trash-index-page"><i class="far fa-trash-alt"></i></button>
</form>
我想将 Sweet Alert2 用于“你确定”弹出消息;到目前为止我有这个,虽然我不确定如何将内联方法 DELETE/POST 转换为 Sweet Alert result.isConfirmed 函数
<form id="btn-form" action="/thought/<%- thought._id %>?_method=DELETE" method="POST" onclick="ConfirmDelete()">
<button class="btn-none trash-index-page"><i class="far fa-trash-alt"></i></button>
</form>
function ConfirmDelete() {
return confirm('Are you sure you wish to delete this record?');
Swal.fire({
title: 'Are you sure you wish to delete this record?',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: 'Yes',
denyButtonText: 'No',
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
Swal.fire('Record deleted!', '', 'success')
} else if (result.isDenied) {
Swal.fire('Record not deleted', '', 'info')
}
})
}