【发布时间】:2020-01-27 13:37:04
【问题描述】:
我有一个 JSON 对象数组,如下所示:
columns: [{
id: 'id',
header: 'Employee ID',
value: 'id'
},
{
id: 'name',
header: 'Employee Name',
value: 'name'
},
{
id: 'address',
header: 'Employee address',
value: 'info.address'
},
]
在 HTML 文件中,我循环遍历数组如下:
<ng-container *ngFor="let eachCol of columns" matColumnDef="{{eachCol.id}}">
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{eachCol.header}}</th>
<td mat-cell *matCellDef="let row">
{{ row[eachCol.value] }}
</td>
</ng-container>
这适用于最高级别 1 的 JSON 值,即它适用于 id 和 name。我正确地获得了员工 ID 和员工姓名。我得到“info.address”的空输出。 "info.address" 被读取为字符串。
【问题讨论】:
-
您无法访问地址 info.address 之类的属性。你所做的相当于row["info.address"],而不是分层搜索,而是直接查找属性info.address。
标签: javascript json angular angular-material