gpt4 book ai didi

javascript - 如何阻止 dropzone 删除我的文件?

转载 作者:行者123 更新时间:2023-11-27 22:51:42 26 4
gpt4 key购买 nike

我配置了 dropzone 的“removedfile”事件。
但在该函数中,我从服务器中删除了该文件。

如果服务器删除文件失败,
然后我希望 dropzone 事件取消从 dropzone 元素窗口删除文件。

这可能吗?

这是我的删除代码

this.on('removedfile', function(file) {
//remove file from server
if (file.status == 'success') {
var model = {
contractId: contractId,
clientId: scope.currentClientId,
fileName: file.name
};
scope.ajaxPost(scope.enumControllers.deleteContractAttachment, model, function(response) {
response.error == false ? tp.showAlert(response.Message, 'success') : tp.showAlert(response.Message, 'error');;
});
}
});

最佳答案

我遇到了问题并解决了它。
您需要修改源代码。

1:覆盖removedfile事件。将删除功能添加到 Dropzone 选项,如下所示:

new Dropzone({
// options
removefile: function(){
// remove from server...
}
});

2:在removeFile函数中: 删除此代码: this.files = without(this.files, file);

3:将without移动到dropzone.prototype:

Dropzone.prototype.without = function(list, rejectedItem) {//...}

last:这是我的removedfile函数(它不是init函数的事件,而是dropzone选项的一个选项):

removedfile: function (file) {
var _ref,
isFileUploadSuccess = (file.status === Dropzone.SUCCESS),
isDeleteSuccess;
if (isFileUploadSuccess) {
customOptions && typeof customOptions.removeFunc === "function" && (isDeleteSuccess = customOptions.removeFunc(file));
}
if ((isFileUploadSuccess && isDeleteSuccess || !isFileUploadSuccess) && file.previewElement && (_ref = file.previewElement) !== null) {
_ref.parentNode.removeChild(file.previewElement);
this.files = this.without(this.files, file);
}
return this._updateMaxFilesReachedClass();
}

removeFunc 是我通过ajax ( async:false ) 从服务器删除文件的函数,因此无论文件是否成功删除,我都可以收到结果;

也许我的代码不太好,但它解决了我的问题。

关于javascript - 如何阻止 dropzone 删除我的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38000795/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com