typescript - 单击离子上的按钮后禁用复选框
问题描述
我正在制作一个 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;
}
}
}
解决方案
您正在尝试遍历值,但它是一个空数组。似乎您在这里缺少核心编程概念。
推荐阅读
- git - Git - 为什么有些客户端在分阶段更改时不能应用存储
- c++ - std::thread 中抛出的异常无法触发 SetUnhandledExceptionFilter 设置的函数
- struct - TypeError:函数中返回参数的数据位置必须是“内存”,但没有给出
- python - 如何在 jupyter notebook 中读取 ODS 文件?如果有办法,我可以在其中使用所有参数,如 pandas.read_excel 中的 skiprows 吗?
- python - 从 Pandas 的列中提取字符串和相对浮点数
- react-native - Expo自动填充OTP SMS在应用程序中
- roku - Roku:在 PosterGrid 中的项目顶部添加图标/图像
- powershell - PowerShell 不使用参数
- android - How to set an ImageButton background color to a specific color of a theme that could be adapted to the night mode?
- javascript - Downloading multiple files from url using NodeJs