我有一段代码用于检查是否存在重复的号码。如果是这样,它将不会将数据保存到数据库中,但是当满足条件时,在Chrome调试中,不会执行行:return,而是跳转到isSaving = true行。我该如何解决?
checkFloorNumber(buildingId: any) {
if (buildingId !== undefined) {
this.buildingService.findAllFloors(buildingId).subscribe((res:
HttpResponse<IFloor[]>) => {
let floors = res.body;
for (let i = 0; i < floors.length; i++) {
if (floors[i].floorNumber == this.floor.floorNumber) {
//this.floor.floorNumber = null;
this.isDuplicate = true;
break;
}
}
});
}
}
save() {
this.checkFloorNumber(this.floor.buildingId);
if(this.isDuplicate === true) {
console.log("asd");
return;
}
this.isSaving = true;
}