Jquery Blueimp – удалить файл из очереди

Во-первых, я должен сказать, что у меня есть все решения в 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, но мне нужно, чтобы все файлы загружались одной кнопкой.... Хм... Спасибо за помощь.


person user1223484    schedule 22.05.2015    source источник


Ответы (1)


Я нашел, как это работает отлично. С небольшой помощью массива он прекрасно работает.

            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;
                }
            }).

Вот и все... Спасибо

person user1223484    schedule 22.05.2015