2014-08-27 87 views
2

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

$('#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(); 
      }); 
     } 
    } 
} 
}); 
+1

'bootbox.confirm'是一个异步方法 - 你需要使用一个回调函数来处理它的结果。 – CBroe 2014-08-27 14:46:16

+0

您是否检查了控制台的错误消息? – Cfreak 2014-08-27 14:46:18

+0

感谢您的帮助 – 2014-08-27 16:09:31

回答

1

的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(); 
     }); 
    } 
} 
+0

谢谢,我使用了CemOzer代码。 – 2014-08-27 16:08:29

1

你必须以确定的确认和提示对话框用户反应使用的回调。 这是确认的签名: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(); 
       }); 
      } 
     } 
    }); 
} 
}); 
+0

啊,我几乎都很讨厌它,非常感谢你的帮助。 – 2014-08-27 16:07:47

+0

但有一件事,如果我检查了很多文件,并在bootbox中单击确定。确认确认将弹出每个文件。有没有办法删除多个文件只需一个确定的点击?谢谢。 – 2014-08-27 16:30:05

+0

如果没有完整的代码或者你的设计,我不能说太多。您可以使用复选框查看文件,然后在确认后删除已选中的文件。 – 2014-08-28 06:10:49