我无法使用angular js ng-repeat指令在我的html表中显示以下json数据
<thead>
<tr>
<th ng-repeat="(header, value) in gridheader">{{value}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in data">
<span ng-repeat="r in row track by $index" >
<td>{{row[r].TrnId}}</td>
<td>{{row[r].TrnDate}}</td>
<td>{{row[r].SavingsMonth}}</td>
<td>{{row[r].SavingsYear}}</td>
<td>{{row[r].AccountName}}</td>
<td>{{row[r].SavingsAdded}}</td>
<td>{{row[r].SavingsRemoved}}</td>
<td>{{row[r].SavingsRunningBalance}}</td>
</span>
</tr>
</tbody>
我从一个有角度的JS控制器中选择了这个Json数据,而resolve对象返回的结果如下所示。这真的让我在不眠之夜的旋风中破译了,但徒劳无功 Json数据:
{
"rows": [
{
"TrnId": 217,
"TrnDate": "2016-12-30T21:00:00.000Z",
"SavingsMonth": "DECEMBER",
"SavingsYear": "2016",
"AccountName": "ABELUN STEPHENSON",
"SavingsAdded": "3100000.0",
"SavingsRemoved": "50000",
"SavingsRunningBalance": "3050000"
},
{
"TrnId": 218,
"TrnDate": "2016-12-30T21:00:00.000Z",
"SavingsMonth": "DECEMBER",
"SavingsYear": "2016",
"AccountName": "ACAN MOLLY NINA",
"SavingsAdded": "3100000.0",
"SavingsRemoved": "50000",
"SavingsRunningBalance": "3050000"
},
{
"TrnId": 219,
"TrnDate": "2016-12-30T21:00:00.000Z",
"SavingsMonth": "DECEMBER",
"SavingsYear": "2016",
"AccountName": "ADONYO HARRIET TIWAALI",
"SavingsAdded": "5100000.0",
"SavingsRemoved": "-",
"SavingsRunningBalance": "5100000"
},
{
"TrnId": 6558,
"TrnDate": "2018-12-30T21:00:00.000Z",
"SavingsMonth": "DECEMBER",
"SavingsYear": "2018",
"AccountName": "SANYA BRIAN",
"SavingsAdded": "-",
"SavingsRemoved": "45000.0",
"SavingsRunningBalance": "205000.0"
}
]
}
我尝试了所有可能的方法,但徒劳
答案 0 :(得分:1)
假设您的json存储在控制器中的$ scope.data变量中,则以下代码应该有效:
<thead>
<tr>
<th ng-repeat="(header, value) in gridheader">{{value}}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in data.rows">
<td>{{row.TrnId}}</td>
<td>{{row.TrnDate}}</td>
<td>{{row.SavingsMonth}}</td>
<td>{{row.SavingsYear}}</td>
<td>{{row.AccountName}}</td>
<td>{{row.SavingsAdded}}</td>
<td>{{row.SavingsRemoved}}</td>
<td>{{row.SavingsRunningBalance}}</td>
</tr>
</tbody>