我正在使用最新版本的PrimeNG。由于不推荐使用DataTable,因此我不得不使用新的TurboTable来显示搜索结果。
<div *ngIf="result | async as resultlist">
<p-table #searchResults class="searchResults" [value]="resultlist?.data.content" [paginator]="true" [rows]="20" (onLazyLoad)="loadLazy($event)" [lazy]="true" [totalRecords]="resultlist?.data.totalElements" >
loadLazy(event) {
if(event.first !== undefined && event.rows !== undefined){
let newPage = (event.first / event.rows) + 1;
// prevent from sending the same request multiple times
if(newPage !== this.pageParams.page){
this.pageParams.page = newPage;
this.loadSearchResults();
}
}
}
loadSearchResults()
{
this.queryParams.page = this.pageParams.page;
this.queryParams.size = this.pageParams.page_size;
this.result = this.sucheService.search(this.queryParams);
}
search(map: { [key: string]: string }): Observable<CollectionContextPartner> {
const httpParams = Object.keys(map)
.reduce((param, key) => param.set(key, map[key]), new HttpParams());
return this.http.get(this.baseUrl + "search", { params: httpParams });
}
第1页的初始请求(由ngOnInit触发)可以正常工作。当我切换到第二页并触发onLazyLoad
事件时,在对页面2进行新的http请求后,整个页面将重新加载。
我只得到以下引用到第一个代码示例的异常:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: [object Object]'. Current value: 'ngIf: null'.