我尝试使用 Angular 和 ng-repeat 从 Ajax json 加载一个 HTML 表格。 我的问题是 JSON 有点复杂,我不知道如何访问“informationstyp”,这是我想在表格中显示的内容。 JSON 的根(“值”)是一个列表。下一级(“informationstyper”)也是一个列表。
如何将“informationstyp”放入表中? 我应该在我的 html 中写什么而不是 {{data.arendeslagId}}?
我想要在我的表中的是:
FK1002
FK1003
FK1004
感谢您的帮助。
我的 html:
<table class="table table-hover">
<thead>
<tr>
<th>Arendeslagid</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="data in infotyper">
<td>{{data.arendeslagId}}</td>
</tr>
</tbody>
</table>
我的 JavaScript:
$scope.infotyper = "";
$scope.invoke = function() {
$.ajax({
"cache": false,
"async": true,
"crossDomain": true,
"url": url",
"method": "POST",
"headers": {
"cache-control": "no-cache",
},
success: function (response) {
$scope.infotyper= response;
}
});
};
我的 JSON 响应:
最佳答案
试着改变这个:
success: function (response) {
$scope.infotyper= response;
}
对此:
success: function (response) {
$scope.infotyper= response.values;
$scope.$apply();
}
如果您使用的是 AngularJS,我强烈建议您使用 $http
服务代替 jQuery 进行 AJAX 请求
关于javascript - 使用 angular 和 ng-repeat 从 Ajax JSON 加载表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44359346/