angular - 如何使用 Angular 8 中的列规范将任何对象传递到通用概述中?
问题描述
我正在尝试创建一个可以接受任何模型的概述,并在 Angular 中使用来自该模型的数据填充网格。
假设我有以下模型:
export class Incident {
id: number;
number: number;
reportDate: string;
startDate: string;
endDate: string;
vehicleNumber: number;
licensePlate: string;
location: string;
supplier: string;
pickupLocation: string;
causeOfFailure: string;
cause: string;
descriptionExternal: string;
status: string;
}
我有一个服务将此数据作为 Json 返回,并且它被映射到事件对象数组。
概述是根据我传递给组件的设置构建的,如下所示:
export class OverviewSettings {
title: string;
collapsible: boolean;
pagination: boolean;
pageSize: number;
primaryColumnSpecifications: ColumnSpecifications[];
rowItems: any[];
}
和 ColumnSpecifications:
export class ColumnSpecifications {
name: string;
dataType: number;
columnSize: string;
}
我将在概述中循环浏览的项目是 any[] 类型,因为我需要它能够处理我传递给它的每个模型。现在我正在传递一系列事件。
我想要实现的目标是能够传递哪一列将显示我的模型中的哪个属性。
我的问题是:如何使此概述可用于所有模型?
解决方案
你能举一个你想做的例子吗?
泛型类的示例:
class KeyValuePair<T,U>
{
private key: T;
private val: U;
setKeyValue(key: T, val: U): void {
this.key = key;
this.val = val;
}
}
class Department<T> {
//different types of employees
private employees:Array<T> = new Array<T>();
public add(employee: T): void {
this.employees.push(employee);
}
}
推荐阅读
- javascript - Vuex axios调用无法处理422响应
- php - Mac M1 无法将 PHP 8.0 映射为 PhpStorm 中的 CLI 解释器
- sql - 数据连接向导未加载
- java - Rest Template Exchange 不在 docker 容器内工作,但在外部工作
- python - 如何合并从word文档中读取的表中的行?
- r - 如何在列表 R 中使用 group_by(或类似命令)
- python - 将单个列表添加到字典中,
- python - Openpyxl:如何获取特定列的值?
- python - 在 Pandas 中获取频率和运行总和、运行总和百分比?
- parsing - 如何反驳 LL(3) 的语法?