【发布时间】:2021-01-25 21:42:21
【问题描述】:
在我的 Angular 应用程序中,我使用了一个表,我必须将行值(一个字符串数组)映射到一个键值对。请指导我。
HTML
<table mat-table [dataSource]="dataSource">
<ng-container matColumnDef="data">
<th mat-header-cell *matHeaderCellDef class="bottom-primary-color"> Data </th>
<td mat-cell *matCellDef="let row" width="150px" > {{displayData[row.data]}} </td>
</ng-container>
</table>
TS
get displayData(): Record<string, string> {
return {
test1: 'testtest1',
test2: 'testtest2',
test3: 'testtest3',
};
}
我想实现这个。
data = [test1, test2, test3];
我想将数组data 与displayData 对象映射并显示
testtest1, testtest2, testtest3 而不是 test1,test2,test3 对于我的用户。
我只能为数组中的第一个元素映射键值对。如何为数组的所有元素映射键值对?
【问题讨论】:
标签: javascript html arrays