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

标签 javascript jquery angularjs json angularjs-ng-repeat

我尝试使用 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/

相关文章:

javascript - 安全差异 jquery 表单提交与 ajax 发布?

javascript - 如何通过函数阻止激活 mousedown 事件?

javascript - 如何在 macos Catalina 上永久安装 NVM?

javascript - jquery 我使用 .css() 将最小高度缩放到窗口高度的错误在哪里

php - 如何从选择的 Jquery 中提取数组输出中的多个值

javascript - “fn”不是 Angular 和 Webpack 的函数

javascript - 通过在 AngularJS 中使用 $http,我们可以在文本文件中写入错误或异常消息吗?

javascript - macrodef 与脚本与 javascript

javascript - 如何使 Canvas 背景透明

javascript - 在 Google Sheet 脚本中调用服务器端函数后关闭 HTML 页面