首页 > 解决方案 > 单击离子上的按钮后禁用复选框

问题描述

我正在制作一个 Ionic 应用程序,并在其上创建配置文件组。为此,用户需要从复选框列表中选择配置文件,然后单击按钮并创建组。此时,那些已经选择的配置文件应该会消失,或者至少应该无法点击它们,但我做不到。代码:HTML

<ion-list>
  <ion-item *ngFor="let profile of profiles; let i = index">
     <ion-label>{{profile.name}}</ion-label>
     <ion-checkbox color="dark" [(ngModel)]="values[i]"></ion-checkbox>
  </ion-item>
</ion-list>
<button ion-button full (click)="addGroup()">Add group</button>

TS

profiles = [];
values = [];
groupList = [];

addGroup(){
let y=0;
for(let i=0; i<this.values.length; i++){
  if(this.values[i] == true){
    this.groupList[y] = this.profiles[i];
    y++;
  }
}
let alert = this.alertCtrl.create({
  title: 'Group created!',
  buttons: ['OK']
});
alert.present();

//I tried this to solve the problem, but it is not really what I want...
for(let i=0; i<this.values.length; i++){
  if(this.values[i] == true){
    this.profiles[i] = 0;
  }
}
}

标签: typescriptionic-frameworkcheckboxclick

解决方案


您正在尝试遍历值,但它是一个空数组。似乎您在这里缺少核心编程概念。


推荐阅读