angular - 如何优化 Ionic 4 中的数据加载 - Angular 7 App
问题描述
我有一个包含 1000 个项目的对象。
我正在 UI 中加载这些数据,但应用程序无法处理如此大量的数据。
有什么方法可以在 Angular 中管理大量数据吗?
这是我的代码:
控制器
import { Component, OnInit } from '@angular/core';
import { bouquetList } from '../../assets/bouquet';
interface BouquetInfo {
name: string;
mrp: number;
channel: string[];
}
export interface Bouquet {
broadcaster: {
name: string;
bouquet: BouquetInfo[];
};
}
@Component({
selector: 'app-bouquet',
templateUrl: './bouquet.page.html',
styleUrls: ['./bouquet.page.scss'],
})
export class BouquetPage implements OnInit {
bouquets: Bouquet[] = bouquetList; // assiging a const of large data
constructor() { }
}
html
<mat-accordion>
<mat-expansion-panel *ngFor="let bouquet of bouquets" >
<mat-expansion-panel-header>
<mat-panel-title>
{{bouquet.broadcaster.name}} |
{{bouquet.broadcaster.bouquet.length }}
</mat-panel-title>
<mat-panel-description>
</mat-panel-description>
</mat-expansion-panel-header>
<div *ngIf="!currentBouquet[0]; then thenBlock else elseBlock"></div>
<ng-template #thenBlock>Loading...</ng-template>
<ng-template #elseBlock>
<mat-accordion>
<mat-expansion-panel *ngFor="let channel of bouquet.broadcaster.bouquet">
<mat-expansion-panel-header>
<mat-panel-title>
{{channel.name}}
</mat-panel-title>
<mat-panel-description>
{{channel.mrp | currency: 'INR' }}
</mat-panel-description>
</mat-expansion-panel-header>
<mat-list role="list" *ngFor="let item of channel.channel; let i=index">
<mat-list-item role="listitem">{{i + 1}}. {{item}}</mat-list-item>
</mat-list>
</mat-expansion-panel>
</mat-accordion>
</ng-template>
</mat-expansion-panel>
</mat-accordion>
您的想法的UI
解决方案
我会生成一个仅顶级索引,将主要数据卸载到 Firebase 之类的东西,然后在索引上查询主要记录。它超级快。
推荐阅读
- kotlin - Android RecyclerView NotifyDataSetChanged 与 LiveData
- c - 尽管从 pthread_create() 返回成功,但没有创建线程
- python - 如何为 aws-lambda python API 生成招摇文档?
- android - setValue() 函数具有未解析的引用
- c# - Elasticsearch 索引文档,但下一个查询返回 0 个命中
- python - 使用 conda 从 tensorflow 1.14.0 升级到 2.2.0 时发生大量包更改
- c++ - 我有一个世界点列表(XYZ),我想在 openGL 窗口中显示它们
- r - 如何将使用 UNIX 纪元秒的 X 轴格式化为 R 中的年/月?
- python - 如何使用 Python 读取邮件的邮件正文?
- cypress - 在 cy.visit 之前执行 cy.request 似乎会导致 cy.visit 失败