2011-04-14 4 views
7

jQuery 파일 업 로더 : https://github.com/blueimp/jQuery-File-UploadjQuery, 플러그인이 이미 div에 적용되었는지 확인하는 방법은 무엇입니까?

위의 플러그인을 사용하고 있습니다. jQuery는 어떻게 fileUpload가 이미 적용되었는지 확인할 수 있습니까?

는 이제 다음과 같은 오류가 발생합니다 :

Uncaught FileUpload with namespace "file_upload" already assigned to this element 
jQuery.jQuery.extend._Deferred.deferred.resolveWithjquery-1.5.1.js:869 
donejquery-1.5.1.js:6591 
jQuery.ajaxTransport.send.callbackjquery-1.5.1.js:7382 

제 기능을하기 전에 확인하는 방법이 호출된다

$('.upload').fileUploadUI({ 
......... 
......... 
......... 

감사

당신은 추가 할 수 있습니다

답변

16

/A와 같은 클래스를 설정 종류의 국기. yoavmatchulsky 아래 지적이 경우, 우리는 jQuery를 파일 업로드 저장합니다 플러그인

$('.upload:not(.applied)').addClass('applied').fileUploadUI({...}); 
+5

을하거나 $를 사용할 수 있습니다 ('. 업로드 : (.applied되지 않음)') .fileUploadUI (...) – yoavmatchulsky

2

당신은 또한보다 쉽게 ​​할 수있는 업데이트applied

//scroll through each upload item 
$('.upload').each(function(){ 

    //Make sure class is not found 
    if (!$(this).hasClass('applied')) 

     //Apply Class and Upload Plugin 
     $(this).addClass('applied').fileUploadUI({...}); 
}); 

라는 클래스를 추가 할 것 FileUpload 핸들러는 jQuery data 개체로 참조됩니다.
"이 요소에 이미 할당 된"file_upload "네임 스페이스가있는 FileUpload"라는 오류 메시지는이 데이터 참조에 대한 플러그인 자체 검사에서 제공됩니다.

당신은이 오류 방지하기 위해 다음과 같은 방법으로 플러그인 초기화 할 수 있습니다 :

$('.upload').not(function() { return $(this).data('file_upload'); }).fileUploadUI({/*...*/}); 
+0

고마워요,이게 내 문제를 해결했습니다. –

2

당신은이

if(undefined != $('.upload').data('blueimp-fileupload')){ 
    console.log('plugin already applied to the element'); 
} 
else console.log('plugin not applied to the element'); 
+1

이 답변을해야합니다. 때로는 코드를 수정할 권한이 없습니다. (생각, 제 3 자 코드의 셀레늄 테스트.) –

+1

간단하고 아름다운! –

관련 문제