2013-09-05 3 views
2

필자는 plupload의 행을 정렬해야하는 요구 사항이 있습니다. 코드 (sortable : true)을 추가했는데 이제는 작동 중입니다. 이제 정렬 순서를 알고 싶습니다. 도움이 될 것입니다.plupload에서 정렬 된 행의 순서를 얻는 방법

+0

가 확실하지 난 당신의 질문을 이해합니다. 내가 아는 한 uploader.files 속성은 UI에 표시되는 내용을 반영하도록 재정렬됩니다. 그것은 당신이 찾고있는 것입니까? – jbl

+0

@jbl 예. 당신이 맞습니다. 하지만 나는 그 순서대로하고 싶다. 예를 들어 내가 4 파일 (1234 주문)을 업로드 한 다음 1에서 4까지를 재배치 한 다음 새 주문 (주문 2341)입니다.이 숫자는 정확하게 필요합니다. – Prathiesh

답변

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); 
     }); 
+0

나는 이것을 이루려고 노력하고 있습니다. 내일 아침 당신에게 도움을 청합니다. @jbl – Prathiesh

0

Plupload 2.1 jQuery를 UI 위젯을 사용하는 경우가 :

uploader.bind('BeforeUpload', function (up, file) { 
    var index = $('#uploader_filelist li').index($('#' + file.id)); 
}); 
관련 문제