angular - 如何使用 ngFor 显示多维数组?
问题描述
我正在使用下面的 Json 显示数据。它在显示第三个内部数组时工作正常,最多两个数组我收到错误。请建议我如何成功检索它。
<tr *ngFor="let priceRowData of solutionData.groups.requestDetails ;let $index=index ">
<td>{{priceRowData.ReqId}}</td>
</tr>
新 Json:解决方案详细信息 -> 组 -> 请求详细信息
{
"SolutionsDetail": [
{
"SolutionId": 658,
"name": "dk",
"id": 1568377327000,
"groups": [
{
"GroupId": 1,
"requestDetails": [
{
"ReqId": 2331,
},
]
}
]
}
]
}
我只想在 UI 中显示所有请求详细信息 id。我怎么能在这里做到这一点。
解决方案
您可以通过属性访问直接访问数组的元素。由于存在三个嵌套数组,因此您必须循环所有这些数组才能访问它们的属性。因此,您将不得不使用 3 个嵌套ngFor
指令来动态列出所有元素。
html
<tr *ngFor="let priceRowData of SolutionsDetail">
<ng-container *ngFor="let group of priceRowData.groups">
<ng-container *ngFor="let requestDetail of group.requestDetails">
<td>{{requestDetail.ReqId}}</td>
</ng-container>
</ng-container>
</tr>
推荐阅读
- java - 包 org.mortbay.http 不存在。如何在 pom.xml 中为此添加依赖项
- amazon-web-services - 如何调试连接问题:从 VPC 中的 Lambda 函数连接到 SSM VPC 端点
- dart - 如何在 Flutter 中隐藏 TextField 底部的字母计数器
- pandas - Pandas:如何显示列的最大差异?
- android - java.lang.Throwable:Sqlite 数据库中的堆栈跟踪
- hyperledger-fabric - 去中心化登录到超级账本结构网络的最佳选择是什么?
- c# - 使用 Nlog 将自定义对象写入 sql server 数据库表
- excel - Excel 与 IFS 和 AND/OR 连接
- serverless-framework - 在无服务器上为 lambda 函数配置 SQS 触发器
- android - 两个标签及其在 Android 自定义键盘上的点击操作