【发布时间】:2015-08-10 14:09:19
【问题描述】:
在一个页面中,我有两个单选按钮,这两个单选按钮产生不同的结果:
第一个按钮是关于学生详细信息的。我的 json 数组如下所示:
[{"Name":"A", "Class":"x", "Section":"abcd", "DOB": "XYZ"},
{"Name":"B", "Class":"x", "Section":"abcd", "DOB": "XYZ"},
{"Name":"C", "Class":"x", "Section":"abcd", "DOB": "XYZ"},
{"Name":"D", "Class":"x", "Section":"abcd", "DOB": "XYZ"}]
我的第二个按钮是学术细节。我的 json 数组如下所示:
[{"Name":"A", "Language":"x", "English":"90", "Maths": "90"},
{"Name":"B", "Language":"x", "English":"80", "Maths": "80"},
{"Name":"C", "Language":"x", "English":"70", "Maths": "70"},
{"Name":"D", "Language":"x", "English":"60", "Maths": "60"}]
以前我遵循类似这样的代码
<body>
<div ng-app="" ng-init='names = [{"Name":"A", "Class":"x", "Section":"abcd", "DOB": "XYZ"},
{"Name ":"B ", "Class ":"x ", "Section ":"abcd ", "DOB ": "XYZ "},
{"Name ":"C ", "Class ":"x ", "Section ":"abcd ", "DOB ": "XYZ "},
{"Name ":"D ", "Class ":"x ", "Section ":"abcd ", "DOB ": "XYZ "}];'>
<table border="2px">
<tr>
<th>
Name
</th>
<th>
Class
</th>
<th>
Section
</th>
<th>
DOB
</th>
</tr>
<tr ng-repeat="x in names">
<td>
{{ x.Name}}
</td>
<td>
{{x.Class}}
</td>
<td>
{{x. Section}}
</td>
<td>
{{x. DOB}}
</td>
</tr>
</table>
</div>
</body>
但是现在表格列和表格值不同了。使用输出 json,我必须动态构建表,因为无法定义表列名。
有人可以帮忙吗?
【问题讨论】:
标签: javascript jquery json angularjs