【发布时间】:2018-05-21 06:08:51
【问题描述】:
插件引导文件输入和SweetAlert2有一些问题
这是为了显示一个对话框来确认用户是否真的要继续删除文件。
如果我要中止删除文件,我需要为 filepredelete 事件返回一个布尔值。该函数是同步的,但我使用的是带有承诺的异步插件 SweetAlert2。
这是我的代码:
$("#gallery-images").fileinput({
...
}).on("filepredelete", function(event, key, jqXHR, data) {
swal({
title: 'Are you sure you want to delete this image?',
showCancelButton: true,
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning',
}).then((result) => {
if(result.value){
return false;
}
return true;
});
});
我找不到等待确认的方法。我正在考虑总是中止删除,并在用户确认时手动删除文件。我需要重构我的代码。
【问题讨论】:
-
您不能等待异步操作返回。我同意唯一的方法是
just always abort the deletion and just manually delete the file when the user confirmed.
标签: javascript sweetalert2 kartik-v