從Web服務中,我得到一個JSON字符串。它可能會根據請求而有所不同。 2 JSON結果被在AngularJS中顯示動態JSON
結果1
[
{
"Key": 1,
"ID": 1,
"applicationId": "1",
"applicationName": "APP1"
},
{
"Key": 2,
"ID": 1,
"applicationId": "2",
"applicationName": "APP2"
}
]
結果2
[
{
"OrgKey": 1,
"ID": 1,
"OrgID": "1",
"OrgName": "Org1"
},
{
"OrgKey": 2,
"ID": 4,
"OrgID": "6",
"OrgName": "Org2"
}
]
如何將我的表格中顯示這個?
在控制器JS文件我用的是$http.get
方法和成功的方法,我把
$scope.resultData = data;
但在HTML我怎麼會顯示動態內容?
<table>
<thead>
<tr>
<th ng-repeat = "result in resultData">
<!-- Not the right way -->
<!-- Here I want to put the headers like "Key,ID" ... -->
</th>
</tr> </thead>
<tbody>
<tr ng-repeat = ""result in resultData">
<td> {{result.Key }} </td>
<!-- When the firlds vary, how to put? ->
</tr>
</tbody>
</table>
可能嗎?如果是這樣如何?謝謝。
看到這個答案,它可以幫助你:http://stackoverflow.com/questions/18357370/angularjs-building-a-dynamic-table- based on a-json/18357643#18357643 –
基於http://docs.angularjs.org/api/ng/service/$http,請確保以正確的方式實現'$ http.get'(異步調用)。否則,HTML將不顯示任何內容。 –
但是那裏的JSON格式是一樣的。 – iCode