Can't use forEach with Filelist

前端 未结 6 624
栀梦
栀梦 2020-12-23 08:56

I\'m trying to loop through a Filelist:

console.log(\'field:\', field.photo.files)
field.photo.files.forEach(file => {
   // looping code
})
         


        
6条回答
  •  清酒与你
    2020-12-23 09:12

    Following code is in Typescript

         urls = new Array();
    
         detectFiles(event) {
           const $image: any = document.querySelector('#file');
           Array.from($image.files).forEach((file: any) => {
           let reader = new FileReader();
           reader.onload = (e: any) => { this.urls.push(e.target.result); }
           reader.readAsDataURL(file);
          }
        }
    

提交回复
热议问题