简体   繁体   English

cdk 虚拟滚动的项目大小

[英]Itemsize of cdk virtual scroll

I noticed when I put the itemSize of the cdk virutal scroll to a lower amount the loading time of the page is almost double the amount.我注意到当我将 cdk 虚拟滚动的 itemSize 设置为较低的值时,页面的加载时间几乎是两倍。

There is a hugh differents between <cdk-virtual-scroll-viewport [itemSize]="45" and <cdk-virtual-scroll-viewport [itemSize]="20" (a table with 2k rows). <cdk-virtual-scroll-viewport [itemSize]="45"<cdk-virtual-scroll-viewport [itemSize]="20" (一个有 2k 行的表格)之间有很大的不同。

My question is why loading of the page goes from 2 seconds to almost 5 seconds?我的问题是为什么页面的加载从 2 秒到将近 5 秒? How can it be such a big differents?怎么会有这么大的不同?

[itemSize] dictates how tall in pixels each row in the list is. [itemSize]指示列表中每行的像素高度。

The virtual scroller then uses this (in part) to determine how many rows it can buffer above and below the viewport.然后虚拟滚动条使用它(部分)来确定它可以在视口上方和下方缓冲多少行。 The less tall you make the itemSize , the more it will try to load and buffer.您使itemSize高度越itemSize ,它尝试加载和缓冲的次数就越多。

As to至于

why loading of the page goes from 2 seconds to almost 5 seconds?为什么页面的加载时间从 2 秒到将近 5 秒?

who knows;谁知道; that depends entirely on what your actual code is and what the list is instantiating and what's bound, what might trigger RecalcStyle, and so on.这完全取决于您的实际代码是什么,列表正在实例化什么,绑定什么,什么可能触发 RecalcStyle,等等。 Maybe you have some process that iterates your list in O(n 2 ), for example, or maybe there are a bunch of event listeners.例如,也许您有一些以 O(n 2 ) 迭代您的列表的过程,或者也许有一堆事件侦听器。 We'd need more detail to analyze that.我们需要更多细节来分析。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM