jquery - 如何使用 JQuery 在 SWAL 中成功调用函数?
问题描述
第二个功能不起作用。它没有收到从第一个函数传递的 id。
这是我的 JQuery 代码。
swal({
title: "Are you sure?",
text: "You will not be able to recover this record!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm) {
if (isConfirm) {
// this.$http.delete();
window.axios.post(`/delete-sl-gl/${brcode}/${slc}/${slt}/${sle}/${cts}`)
.then(response => {
// console.log(response.data.sle)
if (response.data.success === true) {
swal('Deleted', response.data.message, 'success');
//console.log(response.data.sle)
spliceSLE_gl(sle.sle);
}
})
.catch(error =>{
console.log(error.response)
});
} else {
swal("Cancelled", "Your file is safe :)", "error");
}
我在spliceSLE_gl(sle.sle)中遇到错误/被忽略;
解决方案
一个swal实例是一个promise。要根据用户操作添加功能,您必须使用该then()
方法。
这是带有链式catch()和then()方法的 swal 的结构。
swal({
// The swal configuration params
})
// To avoid getting a "cancel" if user click the close button
// or clicks on the overlay (outside the swal)
// "noop" means "no operation".
.catch(swal.noop)
// To handle the confirm/cancel buttons
.then(function (result) {
if (result) {
// Your "confirm" function
}
if (!result) {
// Your "cancel" function
}
});
推荐阅读
- javascript - 如何将嵌套的对象数组展平为数组数组?
- django - 当我进行编辑时,Django 静态文件不会改变我的网站
- android - NestedScrollView 不滚动到底部
- javascript - 从异步 lambda 函数中的回调函数返回值的正确方法是什么?
- javascript - 有没有办法在继续之前等待javascript异步函数完成
- angular - router.navigate 后角度输入无边框底部
- ansible - Ansible 在库存中使用变量
- php - 无法使用 laravel 7 发送密码恢复链接
- c# - NLog 显示 RichTextBoxTarget 对象引用未设置为对象实例
- json - Laravel 添加到 json 响应