angular - 为什么 PrimeNG VirtualScroller loadingItem 不起作用?
问题描述
我有 PrimeNG 11.0.0-rc.2 与 Angular 11 一起使用。我正在使用 VirtualScroller 组件,但我意识到应该显示加载器语句的 loadingItem ng-template 不起作用,即使在他们的示例中,他们也有这个:
<p-virtualScroller [value]="virtualCars" scrollHeight="500px" [itemSize]="150" [rows]="100"
[lazy]="true" (onLazyLoad)="loadCarsLazy($event)">
<ng-template let-car pTemplate="item">
Car content
</ng-template>
<ng-template let-car pTemplate="loadingItem">
Loading...
</ng-template>
</p-virtualScroller>
在组件类中,他们有这个:
export class LazyVirtualScrollerDemo implements OnInit {
virtualCars: Car[];
ngOnInit() {
this.cars = Array.from({length: 10000}).map(() => this.carService.generateCar());
this.virtualCars = Array.from({length: 10000});
}
loadCarsLazy(event: LazyLoadEvent) {
//simulate remote connection with a timeout
setTimeout(() => {
//load data of required page
let loadedCars = this.cars.slice(event.first, (event.first + event.rows));
//populate page of virtual cars
Array.prototype.splice.apply(this.virtualCars, [...[event.first, event.rows], ...loadedCars]);
//trigger change detection
this.virtualCars = [...this.virtualCars];
}, 1000);
}
}
但是 ng-template 中的 Loading... 语句没有显示出来。只是一个空白部分,好像那里什么都没有,然后数据正常到达,但加载时的鬼影效果从未出现。
解决方案
我通过使length
变量 in
this.virtualCars = Array.from({length: 10000});
等于[rows]
HTML 输入变量的值来使加载模板正常工作p-virtual-scroller
。
所以例如
ngOnInit() {
this.virtualCars = Array.from({length: 50});
}
and
<p-virtual-scroller rows = "50"></p-virtual-scroller>
推荐阅读
- c# - 如何将字节 [] 从 blob 上传到 varbinary(max) 到 sql
- node.js - 无法解析“fs”,Angular 的 Truffle Box
- windows - 将文件上传到 S3 存储桶
- kubernetes - 使用现有的 postgres 安装带有 helm chart 的 keycloak
- javascript - 黄瓜世界:尝试构造 h4 元素数组时出错
- html - 如何将div的宽度设置为祖父母div
- javascript - 两个非组之间的正则表达式捕获组
- node.js - Postgres CPU 利用率猛增。对我的案例有任何见解吗?
- python - 如何使用python从网站中提取表格?
- mongodb - 使用 mongorestore 命令恢复转储后如何避免 MongoDB ObjectIds 的自动更新?