gpt4 book ai didi

Jquery Blueimp - 从队列中删除文件

转载 作者:行者123 更新时间:2023-12-01 01:06:52 25 4
gpt4 key购买 nike

首先我必须说我在 stackoverflow 上有所有解决方案,但没有成功。我的问题很简单,我需要在单击“开始上传”按钮之前/之后从队列中删除文件,该按钮一键上传所有文件......我的代码:

            var indexProgressBar = 1;

$('#fileupload').fileupload({
autoUpload: false,
url: url,
dataType: 'json',
sequentialUploads: true,
singleFileUploads: true,
}).on('fileuploadadd', function (e, data) {

$.each(data.files, function (index, file) {
var file = data.files[0];
file.uploadID = 'progress' + indexProgressBar;
file.uploadDivID = 'itemDiv' + indexProgressBar;
file.fileId = 'deleteButton' + indexProgressBar;

var node = $('<div id=' + file.uploadDivID + ' style="margin-bottom:20px; font-size:11px;"><span class="progress-filename" style="width:180px;">' + file.name + '</span ></div>');
node.append('<img src="" id=' + file.fileId + ' alt="delete" /><br />');
node.append('<div id="' + file.uploadID + '" class="progress" style="margin-bottom:0px; width:200px;" ><div class="progress-bar progress-bar-success"></div></div>');
node.appendTo($('#filesToUpload'));

node.find("img").click(function(){
node.remove();
});
});

indexProgressBar++;

//upload Manualy
$("#uploadBtn").on('click', function () {
data.submit();
});
}).on('fileuploaddone', function (e, data) {
//upload Manualy
$("#uploadBtn").off('click');

var uploadDivID = data.files[0].uploadDivID; // returns 'someidentification'

if (data.result.status == "OK") {
$('#' + uploadDivID).fadeOut(1000, function () { $(this).remove(); });
}
else {
$('#' + uploadDivID).append("<div style='color:red'>Error: " + data.result.errorMsg + "</div>");
}

}).on('fileuploadprogress', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
var progressID = data.files[0].uploadID; // returns 'someidentification'

$('#' + progressID + ' .progress-bar').css(
'width',
progress + '%'
);

//}).on('fileuploadprogressall', function (e, data) {
//var progress = parseInt(data.loaded / data.total * 100, 10);
// $('#progress .progress-bar').css(
// 'width',
// progress + '%'
// );

}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');

问题是,这只能在视觉上删除文件,但我需要以某种方式从 data.files 中删除它,但我需要通过一个按钮上传所有文件......嗯......谢谢你的帮助。

最佳答案

我已经发现它是如何完美工作的。在数组的帮助下,它的效果很好。

            var a = [];

var indexProgressBar = 0;

$('#fileupload').fileupload({
autoUpload: false,
url: url,
dataType: 'json',
sequentialUploads: true,
singleFileUploads: true,
}).on('fileuploadadd', function (e, data) {

$.each(data.files, function (index, file) {
var file = data.files[0];
file.uploadID = 'progress' + indexProgressBar;
file.uploadDivID = 'itemDiv' + indexProgressBar;
file.fileId = 'deleteButton' + indexProgressBar;

var node = $('<div id=' + file.uploadDivID + ' style="margin-bottom:20px; font-size:11px;"><span class="progress-filename" style="width:286px; display:inline-block;">' + file.name + '</span ></div>');
node.append('<img src="/_layouts/15/SkodaAuto.MarketingDatabank2.Project/Images/Icons/Delete-12.png" id=' + file.fileId + ' fileId=' + indexProgressBar + ' alt="delete" style="cursor:pointer;" /><br />');
node.append('<div id="' + file.uploadID + '" class="progress" style="margin-bottom:0px; width:300px;" ><div class="progress-bar progress-bar-success"></div></div>');
node.appendTo($('#filesToUpload'));

node.find("img").click(function () {
a.push(file.fileId);
//data.files.splice($("#" + file.fileId).attr("fileId"), 1);

$(this).fadeOut(500, function () {
node.remove();
})

});
});

indexProgressBar++;

//upload Manualy
$("#uploadBtn").on('click', function () {
if ($.inArray(data.files[0].fileId, a) == -1) {
data.submit();
}
});
}).on('fileuploadsend', function (e, data) {
if ($.inArray(data.files[0].fileId, a) != -1) {
return false;
}
}).on('fileuploaddone', function (e, data) {
//upload Manualy
$("#uploadBtn").off('click');

var uploadDivID = data.files[0].uploadDivID; // returns 'someidentification'

if (data.result.status == "OK") {
$('#' + uploadDivID).fadeOut(1000, function () { $(this).remove(); });
}
else {
$('#' + uploadDivID).append("<div style='color:red'>Error: " + data.result.errorMsg + "</div>");
}

}).on('fileuploadprogress', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
var progressID = data.files[0].uploadID; // returns 'someidentification'

$('#' + progressID + ' .progress-bar').css(
'width',
progress + '%'
);

}).on('fileuploadprogressall', function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .progress-bar').css(
'width',
progress + '%'
);
}).prop('disabled', !$.support.fileInput)
.parent().addClass($.support.fileInput ? undefined : 'disabled');

首先我需要指定数组

var a = [];

下一个

 a.push(file.fileId);

接下来是这个

//upload Manualy
$("#uploadBtn").on('click', function () {
if ($.inArray(data.files[0].fileId, a) == -1) {
data.submit();
}
});

还有这个

.on('fileuploadsend', function (e, data) {
if ($.inArray(data.files[0].fileId, a) != -1) {
return false;
}
}).

就是这样...谢谢

关于Jquery Blueimp - 从队列中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30405074/

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