gpt4 book ai didi

javascript - 使用 angular 和 ng-repeat 从 Ajax JSON 加载表

转载 作者:行者123 更新时间:2023-11-30 11:36:05 26 4
gpt4 key购买 nike

我尝试使用 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 响应:

enter image description here

最佳答案

试着改变这个:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com