当我在构造函数中对列表进行排序时,使用Ionic3和virtualScroll工作正常,但是当我在页面上使用排序按钮更改列表的排序顺序时,排序已完成,但列表未刷新。我已经看过virtualTrackBy但是我不确定这是我需要的,因为我的阵列真的在变化。在重新排序之后,如何确保列表刷新?
constructor() {
this.users = this.getUsers();
this.usersSort("FirstName", "(A-Z)"); //Initial state
}
usersSort(key: string, order: string) {
//sort according to key and order
}
configureItem(item: User) {
//display item as "FirstName LastName" or "LastName, FirstName"
}
selectFirst() {
var currentSegment = document.getElementById("segFirst");
var sortOrder;
if (this.segSelected === "FirstName") {
//was already selected --> change sort order
var currentValue = currentSegment.innerText;
sortOrder = currentValue.substr(currentValue.length - 5); // (A-Z) or (Z-A)
} else {
//newly selected
document.getElementById("segLast").innerText = "LastName"; //reset other segment
this.segSelected = 'FirstName';
sortOrder = "(A-Z)"; // (A-Z) or (Z-A)
}
var sortKey = this.segSelected; // FirstName or LastName
var newOrder = (sortOrder === "(A-Z)") ? "(Z-A)" : "(A-Z)";
this.usersSort(sortKey, sortOrder);
var newValue = sortKey + " " + newOrder;
currentSegment.innerText = newValue;
}

<div class="fixed-header my-segment">
<ion-segment [(ngModel)]="segSelected" (ionChange)="changeSegment()">
<ion-segment-button id="segFirst" value="FirstName" (ionSelect)="selectFirst()">FirstName (Z-A)</ion-segment-button>
<ion-segment-button id="segLast" value="LastName" (ionSelect)="selectLast()">LastName </ion-segment-button>
</ion-segment>
</div>
<ion-content class="ion-content-below-my-segment">
<ion-list [virtualScroll]="users">
<button ion-item *virtualItem="let item" (click)="itemSelected(item)">
{{configureItem(item)}}
</button>
</ion-list>
</ion-content>
&#13;
可以找到完整的代码: https://stackblitz.com/edit/ionic-list100k-segment-index
答案 0 :(得分:0)
离子3.5.2存在问题。 用离子3.9.2固定。