gpt4 book ai didi

javascript - 同步调用

转载 作者:行者123 更新时间:2023-12-03 04:44:09 24 4
gpt4 key购买 nike

我想在从服务器下载文件后删除该文件,但是即使我将其放在下载文件行下方,服务中的删除方法也会首先执行,这是我的代码:

generateClearanceExcel(): void {
if (this.selectedIds.length > 0) {
var departureDate = prompt("Please enter departure date.", "");
if (departureDate !== null && departureDate !== "") {
this.generating = true;
this.clearanceService.generateClearanceExcel(this.selectedIds, departureDate).subscribe(
result => {
this.generating = false;
window.location.href = "clearance/downloadreport/?fileName=" + result.fileName;
this.clearanceService.deleteFile(result.fileName).subscribe();

if (result.success == true) {
if (result.infos.length > 0) {
this.alertService.info(result.infos);
}
}
else {
this.alertService.error(result.errors);
}
}
);
}
}
}

TIA。

最佳答案

让我们尝试超时

generateClearanceExcel(): void {
if (this.selectedIds.length > 0) {
var departureDate = prompt("Please enter departure date.", "");
if (departureDate !== null && departureDate !== "") {
this.generating = true;
this.clearanceService.generateClearanceExcel(this.selectedIds, departureDate).subscribe(
result => {
this.generating = false;
window.location.href = "clearance/downloadreport/?fileName=" + result.fileName;
setTimeout(() => {
this.clearanceService.deleteFile(result.fileName).subscribe();
}, 3000);
setTimeout(function(){ }, 3000);

if (result.success == true) {
if (result.infos.length > 0) {
this.alertService.info(result.infos);
}
}
else {
this.alertService.error(result.errors);
}
}
);
}
}
}

关于javascript - 同步调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42944046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com