Front/JS & jQuery

[jQuery][dropzone]dropzone.emit()

오선지♬ 2023. 7. 14. 19:45
728x90
반응형

dropzone.emit("addedfile")는 Dropzone 인스턴스에서 "addedfile" 이벤트를 강제로 발생시키는 방법입니다. 이렇게 하면 Dropzone이 마치 파일이 실제로 추가되었는 것처럼 동작합니다.

 

var myDropzone = new Dropzone("#myDropzone", {
  // Dropzone 설정
});

// "addedfile" 이벤트 강제 발생
myDropzone.emit("addedfile", { name: "example.jpg", size: 1000 });

// 이벤트 처리
myDropzone.on("addedfile", function(file) {
  console.log("파일이 추가되었습니다.", file);
});

 

위 코드에서 myDropzone.emit("addedfile", { name: "example.jpg", size: 1000 }) 부분은 "addedfile" 이벤트를 강제로 발생시키는 부분입니다. 이벤트 핸들러에서 console.log를 사용하여 파일이 추가되었음을 확인할 수 있습니다.

주의할 점은 "addedfile" 이벤트를 강제로 발생시키더라도 실제 파일이 서버로 업로드되지는 않습니다. 이벤트를 통해 파일을 추가한 후에는 실제 파일 업로드를 위해 Dropzone에서 제공하는 업로드 버튼 또는 자동 업로드 설정을 사용해야 합니다.

728x90
반응형

'Front > JS & jQuery' 카테고리의 다른 글

[jquery][datatables] class logic  (0) 2023.07.18
[jQuery] selectBox readonly  (0) 2023.07.15
[jQuery] .first()  (0) 2023.07.10
[jQuery] .detach()  (0) 2023.07.09
[jQuery] .serializeArray()  (0) 2023.07.08