{{member?.testName || 'N/A'}} [{testID: 1, testName: " test1", testAmount: "500-6ren">
gpt4 book ai didi

angular - 如何在 Ionic 3 中获取 ionic 复选框的多选值

转载 作者:行者123 更新时间:2023-12-02 05:29:42 26 4
gpt4 key购买 nike

    <div *ngIf="testList.length > 0">
<ion-item *ngFor="let member of testList">
<ion-label>{{member?.testName || 'N/A'}}</ion-label>
<ion-checkbox color="dark" [(ngModel)]="member.checked"></ion-checkbox>
</ion-item>
</div>

[{testID: 1, testName: " test1", testAmount: "500", testDescription: ""},
{testID: 2, testName: " test2", testAmount: "500", testDescription: ""},
{testID: 3, testName: "dgdfgd", testAmount: "150", testDescription: ""},
{testID: 4, testName: "UricAcid", testAmount: "200", testDescription: ""}]

<button (click)="gettstdata()">Done</button>

如何在单击“完成”按钮时获取所有复选框的值,例如多选

最佳答案

<div *ngIf="testList.length > 0">
<ion-item *ngFor="let member of testList">
<ion-label>{{member?.testName || 'N/A'}}</ion-label>
<ion-checkbox color="dark" (click)="selectMember(member)" [(ngModel)]="member.checked"></ion-checkbox>
</ion-item>
</div>
<button ion-button (click)="checkAll()">Done</button>

在 ts:

  testList: any = [
{testID: 1, testName: " test1", checked: false},
{testID: 2, testName: " test2", checked: false},
{testID: 3, testName: "dgdfgd", checked: false},
{testID: 4, testName: "UricAcid", checked: false}
]

selectedArray :any = [];

checkAll(){
for(let i =0; i <= this.testList.length; i++) {
this.testList[i].checked = true;
}
console.log(this.testList);
}

selectMember(data){
if (data.checked == true) {
this.selectedArray.push(data);
} else {
let newArray = this.selectedArray.filter(function(el) {
return el.testID !== data.testID;
});
this.selectedArray = newArray;
}
console.log(this.selectedArray);
}

关于angular - 如何在 Ionic 3 中获取 ionic 复选框的多选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50399526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com