Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
No se puede iterar sobre la lista de archivos de los elementos soltados en la página web del navegador con DataTransfer

Hay preguntas similares como esta, pero no explican por qué esto falla.

Después de colocar varios archivos en el navegador, la iteración con la instrucción for...of falla mientras funciona el bucle for normal.

El for...of versión genera undefined para file.name mientras que el normal for la versión genera el nombre del archivo correctamente.

¿Por qué?

 function initDragDropEvents() { // Trigger file uploads on drop events. $('body').on('drop', function(e) { let fileList = getFileListFromDropEvent(e.originalEvent); // Have image? Update view. for (const file in fileList) { console.log('1 Dropped file: ' + file.name); } for (let i = 0; i < fileList.length; i++) { console.log('2 Dropped file: ' + fileList[i].name); } }); } function getFileListFromDropEvent(event) { // Prevent default behavior, which opens the file. event.preventDefault(); // Set default result for file. let fileList = []; // Get item list from @event. let itemList = event.dataTransfer.items; if (!itemList) { itemList = event.dataTransfer.files; } if (itemList) { for (const item of itemList) { // Assume DataTransfer interface by default. let file = item; // Use DataTransferItemList interface instead? if (item.kind === 'file') { file = item.getAsFile(); } fileList.push(file); } } return fileList; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto fue causado por un error sutil. En lugar de eliminar la pregunta, publicará la respuesta en caso de que alguien más cometa el mismo error en el futuro.

Esto funciona si usa for...of y no for...in .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!