javascript - 如何使用 ng-repeat 访问嵌套的 json 以构建表
问题描述
我想建立一个看起来像这样的表:table
我在我的数据集中尝试了一些东西,但是由于数据是嵌套的,我不知道如何在我的 html 中使用 ng-repeat 显示它们。
resultsJ1,2,3 和 listnqJ1,2,3 也是列表,因此我们必须能够访问列表的元素
table = [
{ day: " Day1" , webservices : [
{ws: resultsJ1, tnq : listnqJ1 }
]
},
{ day: " Day2", webservices : [
{ws :resultsJ2, tnq : listnqJ2 }
]
},
{ day: " Day3" , webservices : [
{ws :resultsJ3, tnq : listnqJ3 }
]
}
]
$scope.listnqJ1 = tableau[0].webservices[0].tnq;
$scope.listnqJ2 = tableau[1].webservices[0].tnq;
$scope.listnqJ3 = tableau[2].webservices[0].tnq;
$scope.resultsJ1 = tableau[0].webservices[0].ws;
$scope.resultsJ2 = tableau[1].webservices[0].ws;
$scope.resultsJ3 = tableau[2].webservices[0].ws;
self.tableau = tableau
我发现在我的 html 中,它适用于 resultsJ1,2,3 列表,但我在显示第 1、2、3 天的结果时遇到了很大的问题:listnqJ1,2,3。
<table cellpadding="20" rules="GROUPS" frame="BOX">
<thead>
<tr>
<th>Web Service</th>
<th style="width: 100px" ng-repeat="day in ctrl.tableau ">
{{day.jour}}
</th>
</tr>
</thead>
<tbody>
<tr style="width: 100px" class="xl153" ng-repeat="ws in resultsJ1 track by $index">
<td>{{ws}}</td>
<td style="width: 100px" class="xl153" ng-repeat="day in ctrl.tableau" >
<td
style="width: 100px"
class="xl153"
ng-repeat="tnq in listnqJ1 track by $index"
>
{{tnq}}
</td>
</td>
</tr>
<tr class="xl153" ng-repeat="ws in resultsJ2 track by $index">
<td>{{ws}}</td>
</tbody>
</table>
解决方案
推荐阅读
- javascript - dojo 框架中的转轮
- gdb - 如何使 gdb 仅列出调试程序中断时正在执行的线程?
- matlab - CPLEX 错误 5002:%s 不是凸的 - 二进制公式的最小二乘问题
- java - org.springframework.dao.InvalidDataAccessApiUsageException:给定的字符串值:[]无法转换为Json对象
- jquery - 动态添加和删除多个文本框
- javascript - 单击按钮时隐藏 div 并显示 div
- ios - 复制数组中的项目,然后在 swift 中仅在 tableview 中显示每个项目
- python - 为什么未定义 NameError 名称“my_input_value”(Python 2.7)
- php - 在 GitHub 上的 repo 上保存服务器凭据:建议
- arrays - Laravel 合并数组,其中 id 相同