我想在Ionic 3中显示一个列表。数据来自服务器。所以我用ngFor使用了ion-list。通过这种方式,所有项目都立即呈现,滚动不是很平滑。ion-list vs ion-scroll vs virtualScroll in ionic 3
然后我用虚拟滚动如下:
<ion-list [virtualScroll]="hotelsarray" approxItemHeight="220px">
<div tappable *virtualItem="let hotel" class="item-inner-hotel">
<-- Other Code -->
但现在没有项目呈现在所有。 Github上有很多virtualScroll问题。
然后我决定用离子滚动代替离子列表。现在滚动非常快速&平稳。但我也想收听scrollStarted & scrollEnd不在离子滚动的事件。
那么,我应该怎么做才能达到以下效果: - 显示图像列表&项目中的文本。 - 滚动应该很快&平滑。 - ScrollStart & scrollEnd事件,我想听。 - 还应该有一个scrollTo(x,y,time)类似的方法,以便我可以滚动到任何特定的项目。
编辑:这仅适用于iOS。在android中,ngFor的离子列表工作正常&滚动也不错。
EDIT2:粘贴TS码:
public hotelsarray: any; //declaration
this.hotelsarray = []; // in constructor
this.hotelsarray = data.results; //after http call
EDIT3:粘贴HTML片段:
<ion-list [virtualScroll]="hotelsarray" approxItemHeight="220px">
<ion-item *virtualItem="let hotel" class="item-inner-hotel">
<img src="{{hotel.hotelImage}}" class="htl-img">
<h1 class="htl-name">{{hotel.hotelName}}</h1>
<h3 class="htl-prc">{{hotel.hotelPrice}}</h3>
</ion-item>
</ion-list>
Edit4:离子信息 CLI包:(在/ usr/local/lib目录/ node_modules)
@ionic/cli-utils : 1.9.2
ionic (Ionic CLI) : 3.9.2
全球套餐:
Cordova CLI : 6.5.0
本地套餐:
@ionic/app-scripts : 1.3.0
Cordova Platforms : android 6.1.2 browser 4.1.0 ios 4.3.1
Ionic Framework : ionic-angular 3.0.1
系统:
ios-deploy : 1.9.1
ios-sim : 6.0.0
Node : v6.10.2
npm : 3.10.10
OS : macOS Sierra
Xcode : Xcode 8.3.1 Build version 8E1000a
感谢
,你能否告诉了'ts'文件的代码吗? – Sampath
@Sampath,请参阅edit2。 –