我有两个 json 对象,一个是 职位
[
{
"code":"Maxo- 1033",
"title":"Test",
"deleted_by":2,
"updated_at":"2017-08-23 06:32:42"
},
{
"code":"Maxo- 1034",
"title":"Test",
"deleted_by":2,
"updated_at":"2017-08-24 04:55:10"
}
]
其他是标题
[
"code",
"title",
"deleted_by",
"updated_at"
]
我想使用标题数据打印作业数据 就像下面的代码。
<tbody>
<tr ng-repeat = 'job in jobs'>
<td ng-repeat = 'column in headers'>
@{{job.column}} //i want job.code for first iteration and like
</td>
</tr>
</tbody>
预期表输出: 代码标题被 updated_at 删除 Maxo 测试 2 2017-08-23 06:32:42
最佳答案
你可以通过嵌套的 ng-repeat
s 来完成
var app = angular.module('testApp', []);
app.controller('testCtrl', function($scope) {
$scope.jobs = [{
"code": "Maxo- 1033",
"title": "Test",
"deleted_by": 2,
"updated_at": "2017-08-23 06:32:42"
}, {
"code": "Maxo- 1034",
"title": "Test",
"deleted_by": 2,
"updated_at": "2017-08-24 04:55:10"
}];
$scope.headers = [
"code",
"title",
"deleted_by",
"updated_at"
];
});
table, th, td {
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="testApp" ng-controller="testCtrl">
<table>
<tbody>
<tr>
<th ng-repeat="header in headers">{{header}}</th>
</tr>
<tr ng-repeat="job in jobs">
<td ng-repeat="header in headers">{{job[header]}}</td>
</tr>
</tbody>
</table>
</body>
关于javascript - 如何使用嵌套的 ng-repeat 循环两个 JSON 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45853388/