【发布时间】:2018-10-20 13:03:11
【问题描述】:
我已经实现了数组列表。它是从火力基地填充的。我想搜索该列表。第一次加载页面时,它不显示任何列出的项目。但是,如果我在搜索输入中输入一些内容,那么它会显示列表项。我尝试了 ngZone 但它不起作用,这里我将给你完整的源代码。
注意:在搜索中输入内容后,总是显示项目,但最初为空
HTML
<ion-content padding>
<ion-searchbar [(ngModel)]="searchTerm" [formControl]="searchControl" (ionInput)="onSearchInput()"></ion-searchbar>
<div *ngIf="searching" class="spinner-container">
<ion-spinner></ion-spinner>
</div>
<ion-list>
<ion-item *ngFor="let item of items">
{{item.client_meeting_schedule_client_name}}
</ion-item>
</ion-list>
</ion-content>
DONE_TASK.ts
export class DoneTasksPage {
searchTerm: string = '';
searchControl: FormControl;
items: any;
searching: any = false;
constructor(public navCtrl: NavController, public oDataListProvider: DataListProvider, private oNgZone: NgZone) {
this.searchControl = new FormControl();
}
ionViewDidLoad() {
this.setFilteredItems();
this.searchControl.valueChanges.debounceTime(700).subscribe(search => {
this.searching = false;
this.setFilteredItems();
});
}
onSearchInput() {
this.searching = true;
}
setFilteredItems() {
this.oNgZone.run(() => {
this.items = this.oDataListProvider.filterItems(this.searchTerm);
})
}
}
DATA_LIST_PROVIDER
export class DataListProvider {
items = [];
public ClientSchedules: Array<any> = [];
clientSchedulesRef: any;
whereClause: string;
constructor(private oAngularFireDatabase: AngularFireDatabase, private oNgZone: NgZone) {
this.whereClause = "true_false_true_false";
//Client schedule node refference
this.clientSchedulesRef = this.oAngularFireDatabase.database.ref('/Client_meeting_schedule').orderByChild("client_meeting_schedule_valid_status").equalTo(this.whereClause);
//Above sequence of equal IsActive true / IsDelete false / IsDone true / IsNotDone false
this.clientSchedulesRef.on('value', client_Schedules_Snapshot => {
this.oNgZone.run(() => {
// Here we'll work with the list
client_Schedules_Snapshot.forEach(clientsSheduleSnap => {
this.items.push(clientsSheduleSnap.val());
});
});
});
}
filterItems(searchTerm) {
return this.items.filter((item) => {
return item.client_meeting_schedule_client_name.toLowerCase().indexOf(searchTerm.toLowerCase()) > -1;
});
}
}
【问题讨论】:
-
push操作后尝试this.items=[...this.items] -
请给我更多细节@Vikas
-
我的意思是把我分享的代码块放在你的 forEach 方法之后让我知道它是否有效
-
不,它不起作用,我试过了。 @维卡斯
-
可以提供一个stackblitz吗?
标签: angular firebase firebase-realtime-database ionic3