【发布时间】:2020-02-07 15:11:02
【问题描述】:
我正在尝试通过 2 个嵌套的 ngFor 显示 2d 数组
<div class="row" *ngIf="!calculating" style="margin: auto;">
<div class="col-xs-12 col-sm-12 col-md-12 col-sm-offset-1 col-md-offset-2">
<div class="row" *ngFor="let pixelRow of pixels" style="width: max-content;">
<div class="col pixel"
*ngFor="let pixel of pixelRow"
[ngStyle]="{'background-color': pixel.Color }"
(click)="changePixelState(pixel.xIndex, pixel.yIndex)"></div>
</div>
</div>
</div>
基本上它在正常的数据规模上工作正常,但是当它被定义为 1000X1000 时 - 显示需要大量时间,同时页面没有响应。 我曾尝试使用 cdk-virtual-scroll-viewport 但我找不到任何关于如何在二维数组上使用它的文档,只能在一个数据列表中。
我能做什么?有什么想法吗?
【问题讨论】:
-
What can I do? any Ideas?← 限制您的数据。您可以添加分页(或滚动),然后只加载一页数据。这是处理/显示更大数据集的非常正常的机制。没有人可以在任何给定时间“消耗”1000x1000 的数据,因此应用程序没有必要显示这些数据。 -
好吧,我必须同意您的观点,即没有人可以同时使用这么多数据。分页是个好主意。谢谢。
标签: angular performance multidimensional-array ngfor