【发布时间】:2017-06-27 15:56:58
【问题描述】:
我有一个状态列表,其值为: 已调度、打开和关闭。当我点击一个复选框时,我想过滤结果
<ion-item *ngFor="let s of appointmentStatus" >
<ion-checkbox [(ngModel)]="s.checked" (click)="updateFilter(s)"></ion-checkbox>
<ion-label >{{ s.status }}</ion-label>
</ion-item>
<div *ngFor="let a of todaysAppointments>
//list of appointments goes here
我试图想出一种方法来用管道做到这一点,但我还没有找到一个很好的例子,而且我还很新。任何帮助将不胜感激。
if ((appDate.getDay() == currentDate.getDay()) && (appDate.getMonth() == currentDate.getMonth()) && (appDate.getFullYear() == currentDate.getFullYear()) && this.appointments[i].status != 'Pending') {
this.todaysAppointments.push(this.appointments[i]);
}
if ((appDate.getDay() < currentDate.getDay()) && (appDate.getMonth() >= currentDate.getMonth()) && (appDate.getFullYear() >= currentDate.getFullYear()) && this.appointments[i].status != 'Pending') {
this.upcomingAppointments.push(this.appointments[i]);
}
因此,当您只有一个数组时,您在下面所做的工作非常完美。在我的 html 中,我将它分为今天和即将到来的约会。所以我首先加载页面并在相应部分显示所有约会。然后最重要的是,我想通过复选框进行过滤。
<h2 style="background-color:#387ef5">Today's Appointments</h2>
<div *ngFor="let a of todaysAppointments | filter: searchTerm" (click)="openPage(a)">
<h2 style="background-color:#387ef5">Upcoming Appointments</h2>
<div *ngFor="let a of upcomingAppointments | filter: searchTerm" (click)="openPage(a)">
【问题讨论】: