Bootbox Confirm Not Working

Bootbox Confirm Not Working

本文关键字:Working Not Confirm Bootbox      更新时间:2023-09-26

任何人都知道如何解决这个问题。我有这样的代码在删除文件时显示bootbox.conf,但它不起作用。

$('#fileupload').fileupload({
destroy: function (e, data) {
   var that = $(this).data('fileupload');  
      if (bootbox.confirm("Delete this file(s) ?") == true ) {
        if (data.url) {
            $.ajax(data)
                .success(function () {
                      $(this).fadeOut(function () {
                        $(this).remove();
                    });
                });
        } else {
           data.context.fadeOut(function () {
             $(this).remove();
           });
        }
    }
}
});

Bootbox方法不像原生方法那样工作:

bootbox.confirm("Delete this file(s) ?", function(answer) {
    if (!answer) return; // User said "no"
    if (data.url) {
        $.ajax(data)
            .success(function () {
                  $(this).fadeOut(function () {
                    $(this).remove();
                });
            });
    } else {
       data.context.fadeOut(function () {
         $(this).remove();
       });
    }
}

您必须使用回调来确定用户对确认和提示对话框的响应。这是确认的签名:bootbox.confirm(message, callback)

你的代码应该像这个

$('#fileupload').fileupload({
destroy: function (e, data) {
   var that = $(this).data('fileupload');  
      bootbox.confirm("Delete this file(s) ?", function(result) {
        if(result == true){
            if (data.url) {
                $.ajax(data)
                    .success(function () {
                          $(this).fadeOut(function () {
                            $(this).remove();
                        });
                    });
            } else {
               data.context.fadeOut(function () {
                 $(this).remove();
               });
            }
        }
    });
}
});