我正在尝试基于JSON配置生成表。虽然我可以创建表格标题,但我不知道如何按字段名称动态选择行单元格数据。这就是我所拥有的:
.Select( new { Id = Id++, /* plus the rest of your columns */ });
显然{{person.column.fieldName}}不起作用,即这不会转化为person.name和person.age。
有关如何使用列数据中指定的fieldName名称选择person字段的任何想法?
答案 0 :(得分:2)
您可以通过字符串索引器
访问对象属性 obj.name
或obj["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>