gpt4 book ai didi

javascript - 如何使用嵌套的 ng-repeat 循环两个 JSON 对象?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:54 27 4
gpt4 key购买 nike

我有两个 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-repeats 来完成

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com