首页 文章

离子2多项选择,选择所有复选框

提问于
浏览
4

我想要 ion-select 提供选择选项 . 我在第一个位置手动添加了选择所有选项,当我选择所有视图未更新时 . 如何更新视图?

enter image description here
.html

<ion-select multiple="true">
      <ion-option (ionSelect)="allClicked()">select all</ion-option>
      <ion-option *ngFor="let item of students ; let i = index" [selected]="item.checked" [value]="item">{{item.studentName}}</ion-option>
</ion-select>

.ts

allClicked(){
        if(this.isAll){
           console.log(this.isAll)
            this.isAll = false;
            for (let temp of this.students) {
             temp.checked = false;
               }
        }else{
        this.isAll = true;

        for (let temp of this.students) {
           temp.checked = true;
           }
          }
        console.log("all select event ");
        }

1 回答

  • -1

    一个解决方案是将所有学生都放在模型中进行离子选择

    <ion-select multiple="true" [(ngModel)]="selectStudents">
          <ion-option (ionSelect)="allClicked()">select all</ion-option>
          <ion-option *ngFor="let item of students ; let i = index" [selected]="item.checked" [value]="item">{{item.studentName}}</ion-option>
    </ion-select>
    

    ts.

    selectStudents:[];
    function allClicked(){
        selectStudents=[];
        students.filter((data)=>{
           this.selectStudents.push(data.studentName);
        });
    }
    

    我假设学生是一群学生 .

相关问题