问题
I've gone through Ionic 3 docs and I was trying to understand the difference between
https://ionicframework.com/docs/api/components/virtual-scroll/VirtualScroll/
and
https://ionicframework.com/docs/api/components/infinite-scroll/InfiniteScroll/
I see they use different components and while they show an example of InfiniteScroll there is no example of VirtualScroll and it's set up also looks trickier.
What is difference between the two and what are possible use cases when to use one or the other?
回答1:
Virtual Scroll
- We only create enough elements in the
DOMto display the list data that is currently on screen, and we recycle thoseDOMelements to display new data as theyscroll offthe screen. - This is done to improve performance when dealing with long lists.
- Example: you select
500records to be displayed in a list, ButVirtual Scrollwill only insert apercentageof them into theDOMat a time which makes scrolling morefluid.
This diagram should help explain the concept: (by courtesy of josh article below)
Here you can see the example of Virtual Scroll
Infinite Scroll
- When you fetch a set number of records and insert them into a list, once you reach the bottom it'll fetch the next batch and insert them into the list and repeat that as long as you have items to fetch.
- Here you have more
Instance Membersthan theVirtual Scroll. That means you have more control of this component.
Here is an example of Infinite Scroll
Refernces: Link 1 and Link 2
来源:https://stackoverflow.com/questions/46733750/what-are-differences-and-use-cases-for-virtual-vs-infinite-scroll-in-ionic-3