![](/img/trans.png)
[英]Kendo-Angular: Disable select file button in kendo-upload
[英]Kendo Angular upload file with other JSON parameters
在我看來,這個問題的解決方案是自己處理表單,而不是讓控件執行文件上傳。 您應該首先將autoUpload
設置為 false,以防止控件在選擇文件后立即上傳圖像。 然后您可以手動處理select
和remove
事件以控制用戶正在選擇的文件,然后使用文件和其余字段構建您自己的有效負載:
<kendo-upload
[autoUpload]="false"
(select)="handleFileSelected($event)"
(remove)="handleFileRemoved($event)">
</kendo-upload>
在您的.ts
您應該有一個字段來跟蹤文件以及select
和remove
事件的處理程序:
private files: FileInfo[] = [];
handleFileSelected(event: SelectEvent) {
const newFiles = event.files.filter(
(f) => !this.files.find((existingFile) => existingFile.name == f.name)
);
this.files = [...this.files, ...newFiles];
}
handleFileRemoved(event: RemoveEvent) {
this.files = this.files.filter((f) => event.files.indexOf(f) === -1);
}
從您的屏幕截圖中,我可以看到您只需要一個文件,因此處理程序可以變得更簡單:
private file: FileInfo;
handleFileSelected(event: SelectEvent) {
this.file = event.files.slice().shift();
}
handleFileRemoved(event: RemoveEvent) {
this.file = null;
}
然后您可以將文件傳遞給您的服務中的保存方法:
handleSave() {
this.service.saveUpload(
this.uploadTypeId,
this.description,
this.uploadedUserId,
this.file?.rawFile
).subscribe(res => {
console.log('successfully saved', res);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.