Ionic 2如何在单击按钮时检查所有复选框并获取选中的复选框的值 [英] Ionic 2 how to check all checkboxes on button click and get checked checkboxes' value
本文介绍了Ionic 2如何在单击按钮时检查所有复选框并获取选中的复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Angular 2中非常陌生,因此在Ionic 2中还是有一个小问题,有人可以告诉我如何在单击按钮时选中所有复选框吗?以及如何在另一个按钮上单击以获取选中的复选框的价值.
I m fairly new in Angular 2 and hence Ionic 2, I have a little problem, can any body tell me how to check all checkboxes on button click?? and how to get value oc checked checkboxes on another button click.
这是我的html外观
<div class="card item-icon-right" *ngFor="let item of items" >
<ion-checkbox *ngIf="showCheckBoxes" [(ngModel)]="item.id" mode="ios"></ion-checkbox>
</div>
<button class="button button-calm">Check All</button>
<button class="button button-primary">Get selected Values</button>
谢谢
推荐答案
您可以有两个复选框元素
you can have two checkbox elements
- 对于全选"-只需单击一下即可制作所有元素(只需切换)
-
选择特定的
- For select All -to make all the elements based on one click(simply toggle)
Select particular
<div class="card item-icon-right" *ngFor="let item of items" >
<ion-checkbox *ngIf="showCheckBoxes && selectedAll" [(ngModel)]="item.id" mode="ios" [checked]="selectedAll"></ion-checkbox>
<ion-checkbox *ngIf="showCheckBoxes && !selectedAll" [(ngModel)]="item.id" mode="ios" ></ion-checkbox>
</div>
全部选中获取选定的值
checkAll(){
this.selectedAll=true;
console.log(this.items);
}
当您选择所有项目时,您将按原样使用整个数组.
When you are selecting all items then you are using the entire array as such.
这篇关于Ionic 2如何在单击按钮时检查所有复选框并获取选中的复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文