【发布时间】:2021-05-23 02:08:42
【问题描述】:
我有一个 for 循环,它生成了 2 个按钮,两个按钮都根据每行的条件显示或隐藏。出于某种原因,我使用布尔值来满足一个条件,然后所有行都受到影响,但我只希望那个特定的行受到影响。以下是我的代码。该程序是用 ionic Angular 编写的。
前端 HTML 文件
<ion-list *ngFor="let ml of miqaatITS">
<ion-item>
<ion-label><b>{{ml.event}}</b><br>{{ml.date}}<br>{{ml.time}}</ion-label>
<ion-button color="dark" [routerLink]="['/home/Allocation']" *ngIf="isPass">VIEW PASS</ion-button>
<ion-button color="dark" fill="outline" *ngIf="!isPass" disabled>NO PASS</ion-button>
<ion-button color="danger" >CANCEL PASS</ion-button>
</ion-item>
</ion-list>
.ts 文件
isPass = false;
feedData() {
console.log(this.authUser);
this.postData.user_id = this.authUser.user_id;
this.postData.token = this.authUser.token;
this.postData.itsnumber = this.authUser.itsnumber;
if (this.postData.user_id && this.postData.token) {
this.miqaat.miqaatITSData(this.postData).subscribe(
(res: any) => {
console.log(res);
for(var pass of res.miqaatITS){
console.log(pass.allocation == 1);
if(pass.allocation == 1) {
this.isPass = !this.isPass;
}
}
this.miqaat.changeMiqaatData(res.miqaatITS);
},
(error: any) => {
this.toastService.presentToast('Network Issue.');
}
);
}
}
请指教
【问题讨论】:
-
您对 this.isPass 的使用意味着整个班级只有一份副本,而不是每个“miqaatITS”一份。如果这是一个对象,则其上的布尔属性会更好。
标签: javascript angular typescript ionic-framework