【发布时间】:2014-12-24 12:20:25
【问题描述】:
我正在尝试在 blueimp 文件上传脚本中找到位置,以更改表中新文件位置的行为。如何通过添加到文件列表末尾的表格顶部来强制它们?
【问题讨论】:
标签: javascript jquery jquery-file-upload blueimp
我正在尝试在 blueimp 文件上传脚本中找到位置,以更改表中新文件位置的行为。如何通过添加到文件列表末尾的表格顶部来强制它们?
【问题讨论】:
标签: javascript jquery jquery-file-upload blueimp
只需添加属性 prependFiles:true
例子:
$('.fileupload').fileupload({
url: 'your_url',
dataType: 'json',
prependFiles:true
});
【讨论】:
我通过覆盖 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);
});
})
【讨论】: