如何使用Angular 2+实现可配置表

时间:2018-03-09 14:02:38

标签: angular typescript

我正在尝试基于JSON配置生成表。虽然我可以创建表格标题,但我不知道如何按字段名称动态选择行单元格数据。这就是我所拥有的:

.Select( new { Id = Id++, /* plus the rest of your columns */ });

显然{{person.column.fieldName}}不起作用,即这不会转化为person.name和person.age。

有关如何使用列数据中指定的fieldName名称选择person字段的任何想法?

1 个答案:

答案 0 :(得分:2)

您可以通过字符串索引器

访问对象属性

obj.nameobj["name"]

<table> 

    <tr>
        <th *ngFor="let column of columns">{{column.heading}}</th>
    </tr>

    <tr *ngFor="let person of people">
        <td *ngFor="let column of columns">{{person[column.fieldName]}}</td>
    </tr>

</table>