blueimp jQuery 文件上传新文件顺序

zib*_*bra 5 javascript jquery blueimp jquery-file-upload

我正在尝试在 blueimp 文件上传脚本中找到位置,以更改表中新文件位置的行为。如何通过在文件列表末尾插入的表格顶部添加来强制它们?

小智 1

我通过覆盖 fileuploaddone 的事件侦听器并添加前置而不是附加来做到这一点。

看起来像这样

$('.fileupload').fileupload({
        url: 'phpUpload/index.php?customDir='+saveFolder,
        dataType: 'json',
        dropZone: $(this),
        autoUpload: true,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|mp3|mp4|wav|doc|docx|ppt)$/i,
        maxFileSize: 150000000, // 150 MB
        // Enable image resizing, except for Android and Opera,
        // which actually support image resizing, but fail to
        // send Blob objects via XHR requests:
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 100,
        previewMaxHeight: 100,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        // you can leave this out if you want the default design
        data.context = $('<div/>').addClass('existingMediaFile');
        $.each(data.files, function (index, file) {
            var node = $('<a/>').append($('<span/>').text(file.name));
            node.appendTo(data.context);
        });

    }).on('fileuploaddone', function (e, data) {
        $.each(data.result.files, function (index, file) {
            $(data.context.children()[index]).prepend(file.name+' '+file.thumbnailUrl);
        });
    })
Run Code Online (Sandbox Code Playgroud)