将SWAL2添加到我的Spring项目中时遇到问题。我想确认用户删除客户端的决定。
我的代码:
HTML:
<td><a id="clientDeleteConfirmButton" class="btn btn-danger"
onclick="clientDeleteConfirmAlert();" th:value="@{/delete_client/__${client.id}__}">
1_simple-remove"></i></a></td>
控制器:
@RequestMapping(value = "/delete_client/{clientId}")
public String deleteClient(@PathVariable String clientId, @ModelAttribute("deleteClient") Client client) {
client.setId(clientId);
clientRepository.delete(client);
return "redirect:/clients";
}
JS:
<script>
function clientDeleteConfirmAlert(){
const swalWithBootstrapButtons = Swal.mixin({
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false,
});
swalWithBootstrapButtons.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
confirmButtonInput: 'clientConfirmButtonLink'
cancelButtonText: 'No, cancel!',
reverseButtons: true
}).then((result) => {
if (result.value) {
swalWithBootstrapButtons.fire(
'Deleted!',
'Your file has been deleted.',
'success');
}
else if (result.dismiss === Swal.DismissReason.cancel) {
swalWithBootstrapButtons.fire(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
}
</script>
我想从按钮th:value获取href并在脚本onclick ConfirmButton中使用它。我尝试了很多事情,但现在迷路了:(