我有一个角度应用程序,我试图从json创建一个表。我的json如下:
[
{
"campus_id": "321",
"name": "0"
},
{
"campus_id": "231",
"name": "1"
},
{
"campus_id": "123",
"name": "2"
}
]
通常我们会在html中创建一个表,如下所示:
<table class="table table-striped">
<tr>
<th>
Campus id
</th>
<th>
Name
</th>
</tr>
<tr ng-repeat="item in items">
<td >
{{item.campus_id}}
</td>
<td >
{{item.name}}
</td>
</tr>
</table>
如何创建json中的标题而不是自己定义它们?
答案 0 :(得分:1)
我会在json结果中添加列标题,如此
columnDefs: [
{field: 'campus_id', displayName: 'Campus ID'},
{field: 'name', displayName: 'Name'}],
data:
[
{
"campus_id": "57911000",
"name": "0"
},
{
"campus_id": "57911001",
"name": "HIGHLAND PARK HIGH SCHOOL"
},
{
"campus_id": "57911007",
"name": "P A S S Learning Center School"
}
]
否则你可以使用项目&#34;中的键,值配对ng-repeat =&#34;(键,值);使用过滤器返回1行,然后使用{{key}}