以下是代码,它可以帮助您更好地理解问题。 HTML代码: -
{{#each uploadsData as |row|}}
<div {{action 'upload' row uploadsData}} class="mdl-cell mdl-cell--12-col mdl-grid kyc-uploads__form_uploads_documents-grid">
<div class="mdl-cell--2-col mdl-cell--hide-phone kyc-uploads__form_uploads_documents-grid_icon">
{{inline-svg row.svg}}
</div>
<div class="mdl-cell--10-col mdl-cell--12-col-phone kyc-uploads__form_uploads_documents-grid__text">
<span class="mdl-cell--hide-desktop" style="padding: 5%;">{{inline-svg row.svg}}</span>
<span class="kyc-uploads__form_uploads_documents-grid__text_title">{{row.heading}}</span>
<span class="kyc-uploads__form_uploads_documents-grid__text_subText">
{{if (eq row.optional true) "(Optional)" ""}}
</span>
<span class="kyc-uploads__form_uploads_documents-grid__text_select {{if (eq row.isSubmitted true) "kyc-uploads__form_uploads_documents-grid__text_select_completed" ""}}">
<i class="material-icons">done</i>
</span>
</div>
</div>
<input type="file" style="visibility: hidden; display: none;" id="{{row.key}}" name="{{row.key}}" value="{{inputFile}}" />
{{/each}}
JS代码: -
upload(row, uploadsData) {
var el =$('#'+row.key);
el.click();
var file = el[0].files[0];
console.log(file);
if(file != null){
//do something...
});
this.controller.set('isCompleted', completionStatus);
}
当用户点击el.click()
进行文件上传时,会打开一个对话框来选择文件。
现在这里是一个线程自动退出循环的技巧,因为文件尚未被选中而另一个正在要求用户选择一个文件。那么你有什么想法我怎么能等到文件是否为空,直到用户选择文件??