0
我有一个分配给in_timings变量的对象数组。我想检查对象的某些条件,以便为执行做准备。 我不知道我做错了什么,但循环似乎在我没有料到的块上执行。循环遍历一个对象数组并检查它的属性
in_timings:TimeInModel[];
...........
fetchTimeIns(){
this.employeesService.getTimeIn()
.subscribe(result=>this.in_timings = result,
error => this.errorMessage = <any>error);
}
.......................
...............
for(let in_timing of this.in_timings)
{
if(in_timing.employee_id===emp_id && in_timing.is_active===true){
console.log("You have already checked in!");
}
else if((in_timing.employee_id===emp_id && in_timing.is_active===false) || this.in_timings.length<0){
console.log("Add another row here...");
}
else{
console.log("All conditions exhausted!");
}
}
在图像中,它显示第一条语句被执行,最后一条被执行两次。
你预计会发生什么? – toskv
我期望的是,只有一个块要执行。我想要的是,指导如何做到这一点。 – 7Guyo
__要执行的块是什么意思? – sebaferreras