大家好,我正在使用sweetalert2,该功能已经可以使用,但是有些错误需要修复。
错误:
当我单击“确定”时,将触发location.reload()
,而无需单击“确定”。
当我单击“取消”时,模态仍处于弹出模式。
这是我的脚本。
$('body').on('click','.delete-category',function(){
deleteCategory();
});
function deleteCategory(id){
var id = $('body').find('#categoryTable tbody tr.selected .catId').val();
console.log(id);
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then(function(isConfirm){
if (isConfirm) {
$.ajax({
url: `/asset/category-delete/${id}`,
method: 'DELETE',
data: { _token: '{{ csrf_token()}}' },
success: function(data){
swal(
'Deleted!',
'Your file has been deleted.',
'success'
);
location.reload();
},
error: function(err){
swal('Error!','Please report this issue.', 'error');
}
});
} else {
swal("Cancelled","", "error");
}
});
}
正在寻求增强。
答案 0 :(得分:0)
我找到了您可以通过下面提供的“处理取消通知”链接处理取消的示例
swalWithBootstrapButtons({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
reverseButtons: true
}).then((result) => {
if (result.value) {
swalWithBootstrapButtons(
'Deleted!',
'Your file has been deleted.',
'success'
)
} else if (
// Read more about handling dismissals
result.dismiss === swal.DismissReason.cancel
) {
swalWithBootstrapButtons(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
此link帮助您
答案 1 :(得分:0)
关于错误#1:如果要在小号互动之后执行using AudioSwitcher.AudioApi.CoreAudio;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice;
double vol = defaultPlaybackDevice.Volume;
defaultPlaybackDevice.Volume = defaultPlaybackDevice.Volume - 5.0;
defaultPlaybackDevice.Volume = defaultPlaybackDevice.Volume + 5.0;
}
}
,则必须将location.reload();
放在then()
方法中。
success: function(data){
swal(
'Deleted!',
'Your file has been deleted.',
'success'
).then(()=>{
location.reload();
});
},
关于错误#2:我不知道您在说什么«删除模态» ...