mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(virtual-scroll): fixes dynamic changes
This commit is contained in:
@@ -4,18 +4,26 @@
|
||||
<ion-title>
|
||||
Virtual Scroll Test
|
||||
</ion-title>
|
||||
<ion-buttons slot="end">
|
||||
<ion-button (click)="addItems()">
|
||||
<ion-icon name="add" slot="icon-only"></ion-icon>
|
||||
</ion-button>
|
||||
</ion-buttons>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content>
|
||||
<ion-virtual-scroll [items]="items" [headerFn]="myHeaderFn" [footerFn]="myFooterFn">
|
||||
<ion-item-divider *virtualHeader="let header">{{ header }}</ion-item-divider>
|
||||
<ion-item-divider *virtualFooter="let footer">-- {{ footer }}</ion-item-divider>
|
||||
<!-- <ion-item *virtualItem="let item" itemHeight="itemHeight">
|
||||
{{item.name}}
|
||||
</ion-item> -->
|
||||
<ion-item *virtualItem="let item" [routerLink]="['/', 'virtual-scroll-detail', item]">
|
||||
<ion-label>
|
||||
<app-virtual-scroll-inner [value]="item"></app-virtual-scroll-inner>
|
||||
<app-virtual-scroll-inner [value]="item.name"></app-virtual-scroll-inner>
|
||||
</ion-label>
|
||||
<ion-icon *ngIf="(item % 2) === 0" name="airplane" slot="start"></ion-icon>
|
||||
<ion-toggle slot="end" [checked]="(item % 2) === 1"></ion-toggle>
|
||||
<ion-icon *ngIf="(item.name % 2) === 0" name="airplane" slot="start"></ion-icon>
|
||||
<ion-toggle slot="end" [(ngModel)]="item.checked"></ion-toggle>
|
||||
</ion-item>
|
||||
</ion-virtual-scroll>
|
||||
</ion-content>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { HeaderFn } from '@ionic/core';
|
||||
import { IonVirtualScroll } from '@ionic/angular';
|
||||
|
||||
@Component({
|
||||
selector: 'app-virtual-scroll',
|
||||
@@ -7,7 +8,11 @@ import { HeaderFn } from '@ionic/core';
|
||||
})
|
||||
export class VirtualScrollComponent {
|
||||
|
||||
items = Array.from({length: 1000}, (_, i) => i);
|
||||
@ViewChild(IonVirtualScroll) virtualScroll: IonVirtualScroll;
|
||||
|
||||
items = Array.from({length: 100}, (_, i) => ({ name: `${i}`, checked: true}));
|
||||
|
||||
itemHeight = () => 44;
|
||||
|
||||
myHeaderFn: HeaderFn = (_, index) => {
|
||||
if ((index % 10) === 0) {
|
||||
@@ -20,4 +25,12 @@ export class VirtualScrollComponent {
|
||||
return `Footer ${index}`;
|
||||
}
|
||||
}
|
||||
|
||||
addItems() {
|
||||
console.log('adding items');
|
||||
this.items.push(
|
||||
{ name: `New Item`, checked: true}
|
||||
);
|
||||
this.virtualScroll.checkEnd();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user