蓝色印象jQuery文件上传新文件顺序

5

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

2个回答

4
只需添加属性prependFiles:true 例如:
$('.fileupload').fileupload({
    url: 'your_url',
    dataType: 'json',
    prependFiles:true
});

1

我通过覆盖fileuploaddone事件监听器并使用prepend而不是append来实现。

它看起来像这样

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接