2013-02-27 2 views
0

파일 업로드에 Plupload를 사용하고 있습니다. 구체적인 이유 때문에 FilesAdded을 "내부"init과 같이 입력해야합니다.추가 된 요소를 어떻게 바인딩 할 수 있습니까?

문제는 jQuery가 추가 된 요소에 jQuery.remove()을 사용할 수 없다는 것입니다.

.on()을 사용하여 정상적으로 해결했지만 click 등의 작업이 없으므로 첨부 된 요소를 바인딩하는 방법을 모르겠습니다. 많이 감사

모든 지침 : 이것은 remve를 트리거

// Custom example logic 
var uploader = new plupload.Uploader({ 
    runtimes : 'gears,html5,flash,silverlight,browserplus', 
    browse_button : 'btn-file-browse', 
    container : 'drag-drop-container', 
    drop_element : 'drag-drop-container', 
    max_file_size : sim_gal_data['max_file_size'], 
    url : sim_gal_data['upload_url'], 
    multi_selection : true,  
    init : { 
     FilesAdded: function(up, files) { 

      // Create list of files being uploaded 
      jQuery.each(files, function(i, file) { 
       jQuery('#filelist').append(
        '<div id="' + file.id + '" class="file_upload">' + 
        '<div class="file_name">' + file.name + ' (' + plupload.formatSize(file.size) + ')' + 
        '</div> <label class="file_progress"><b></b></label>' 
       ); 
      }); 

      // Ready set go! 
      up.refresh(); 
      up.start(); 
    } 
}); 

업데이트 :

uploader.bind('UploadComplete', function(up, files) { 
    jQuery('#filelist .file_name').remove(); 

    // I'm able to run this - so maybe .file_name is appended? 
    jQuery('#filelist .file_name).append('TEST'); 
}); 
+1

에서이를 처리해야합니다. 제거를 트리거하는 것은 무엇입니까? –

+0

당신의 코드를 제거합니다 – Pete

+0

@ Pete 제 질문에 제거 코드를 추가했습니다 – Steven

답변

0

당신은 UploadComplete에 따라 업을 청소하려고합니까? 그렇다면 아래와 같이되어야합니다. 업로드 한 각 파일에 따라 업을 정리하려는 경우 요소는 당신이 일을해야 remove 메소드를 호출하여 쿼리는 DOM에있는 경우

, 당신은 FileUploaded event handlere

init : { 
    UploadComplete: function(uploader, files){ 
    alert('upload complete'); 
    jQuery('#filelist').html(''); 
    }, 
    FilesAdded: function(up, files) { 

     // Create list of files being uploaded 
     jQuery.each(files, function(i, file) { 
      jQuery('#filelist').append(
       '<div id="' + file.id + '" class="file_upload">' + 
       '<div class="file_name">' + file.name + ' (' + plupload.formatSize(file.size) + ')' + 
       '</div> <label class="file_progress"><b></b></label>' 
      ); 
     }); 

     // Ready set go! 
     up.refresh(); 
     up.start(); 
}