【问题标题】:Angular help for showing data from API用于显示来自 API 的数据的 Angular 帮助
【发布时间】:2017-12-04 05:32:13
【问题描述】:

鉴于以下 JSON 文件: https://drive.google.com/file/d/0Byt0rakzaB6bNXM0RW1ua3owY1U/view?usp=sharing https://drive.google.com/file/d/0Byt0rakzaB6bdEhCSmFnZDBuZlU/view?usp=sharing

创建一个响应式网页以显示上面提供的数据。 要求: 该页面在所有移动设备上都是响应式的 使用Angular JS 1.X作为结构框架

这就是问题所在。我已经像下面这样编码,使它们像截图表。数据显示在控制台中。我可以像所需的屏幕截图一样显示表格中的数据 ..................................................... ...

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
    $http.get("NHL_Goaltenders.json")
    .then(function(response) {
       $scope.myData1 = response;
       console.log(response);
      $http.get("NHL_Skaters.json").then(function(response){
         $scope.myData2 = response;
        console.log(response);
      });
    });
});
</script> 


<div ng-app="myApp" ng-controller="myCtrl"> 
  <!-- <div ng-repeat="x in myData1">
    <p>{{ x.firstname}}</p> -->
<table border="1">

   <tr>

     <td>NAME</td>&nbsp;
     <td>TEAM</td>&nbsp;
     <td>GP</td>&nbsp;
     <td>G</td>&nbsp;
     <td>A</td>&nbsp;
     <td>PTS</td>&nbsp;
  </tr>

  <tr ng-repeat="x in myData1">

     <td>{{ x.Headers[0]}}</td>&nbsp;
     <td>{{ x.Headers[1]}}</td>&nbsp;
     <td>{{ x.Headers[2]}}</td>&nbsp;
     <td>{{ x.Headers[3]}}</td>&nbsp;
     <td>{{ x.Headers[4]}}</td>&nbsp;
     <td>{{ x.Headers[5]}}</td>&nbsp;
  </tr>
    <tr ng-repeat="x in myData1">

     <td>{{ x.Statistics[0][0]}}</td>&nbsp;
     <td>{{ x.Statistics[0]}}</td>&nbsp;
     <td>{{ x.Statistics[2]}}</td>&nbsp;
     <td>{{ x.Statistics[3]}}</td>&nbsp;
     <td>{{ x.Statistics[4]}}</td>&nbsp;
     <td>{{ x.Statistics[5]}}</td>&nbsp;
  </tr>
</table>

</div>

【问题讨论】:

  • 您有问题吗?
  • 仅供参考,您可能是指$scope.myData1 = response.data$scope.myData2 = response.data$http 服务返回的承诺使用 response 对象解析请求,而不是解析的响应正文。见docs.angularjs.org/api/ng/service/$http#general-usage

标签: angularjs json


【解决方案1】:

这是可能的解决方案之一:https://plnkr.co/edit/VahUhdPGF0BQAai9Lwl8?p=preview

  <table border="1">
     <tr>
       <th ng-repeat="header in goaltenders.Headers">{{header}}</th>
    </tr>

    <tr ng-repeat="row in goaltenders.Statistics track by $index">
       <td ng-repeat="item in row track by $index">{{ item }}</td>
    </tr>
  </table>

【讨论】:

  • 感谢 cloudy.one。我只想进行一些修改和 dd 引导类以使其响应。该表将在一个滑块中。你对此有什么建议吗?提前致谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-04
  • 1970-01-01
  • 1970-01-01
  • 2019-06-03
  • 2020-12-18
相关资源
最近更新 更多