我有一个要求,我需要对plupload的行进行排序。我添加了代码(sortable : true)
,现在它正在运行。现在我想知道排序的顺序。
任何帮助将不胜感激。
答案 0 :(得分:2)
您可以尝试在FilesAdded上向文件对象添加initialIndex
属性。稍后在文件对象上查询此属性以了解已执行的排序。
假设uploader
是:
var uploader = $('#uploader').plupload('getUploader');
然后
// add initialIndex property on new files, starting index on previous queue size
uploader.bind('FilesAdded', function(up,files){
for(var i = 0, upPreviousSize = up.files.length - files.length, size = files.length; i<size; i++)
{
files[i]["initialIndex"] = i +upPreviousSize ;
}
//console.log(up.files);
});
// remove the 'holes' in the sequence when removing files
// (if not, next files adding would introduce duplicate initialIndex)
uploader.bind('FilesRemoved', function(up,files){
// process removed files by initialIndex descending
var sort = function(a,b){return b.initialIndex - a.initialIndex;};
files.sort(sort);
for(var i = 0, size = files.length; i<size; i++)
{
var removedFile = files[i];
// update the remaining files indexes
for (var j =0, uploaderLength = up.files.length; j<uploaderLength; j++)
{
var remainingFile = up.files[j];
if(remainingFile["initialIndex"] > removedFile["initialIndex"])
remainingFile["initialIndex"]--;
}
}
//console.log(up.files);
});
答案 1 :(得分:0)
如果使用Plupload 2.1 jQuery UI小部件:
uploader.bind('BeforeUpload', function (up, file) {
var index = $('#uploader_filelist li').index($('#' + file.id));
});