从表中获取没有键的JSON值

时间:2016-03-20 06:22:01

标签: angularjs json

我试图从没有键的json中获取数据到表中。

[
[
"valu10", //row1 col1
"valu11", //row1 col2
"valu12",
"valu13"
],
[
"valu20",
"valu21",
"valu22",
"valu23"
],
[
"valu30",
"valu31",
"valu32",
"valu33"
]
]

在我的成功阻止中,我在警报框中获取数据。如何在角度表中获取这些数据。我尝试了以下操作,

........
}).success(function(data, status, headers, config) {
        var log = [];           

        var data1 = angular.fromJson(eval(data));
        var rowList = data1;
        $scope.rows = rowList;
    }).error(function(data, status, headers, config) {
        alert("error");     
    });

in html:

                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th ng-repeat="header in headers">{{header}}</th>
                            </tr>
                        </thead>
                        <tbody>

                             <tr ng-repeat="item in rows">
                             {{item}}
                            </tr> 
                        </tbody>
                    </table>    

1 个答案:

答案 0 :(得分:1)

我为你创建了一个JSFiddle,希望它能帮助你:

https://jsfiddle.net/oronbdd/h4sor3w4/1/

Angualr控制器:

var app = angular.module('plunker', []);

app.factory('myService', function($http) {
  return {
    async: function() {
      return $http.get('https://api.myjson.com/bins/368hv');  
    }
  };
});

app.controller('MainCtrl', function( myService,$scope) {
    $scope.data = "oron";
  myService.async().then(function(d) { 
    $scope.data = d.data;
  });
});

HTML:

<div ng-app="plunker">
<div ng-controller="MainCtrl">
        JSON:{{data}}<br>

  <br/>
  ANSWER: 

  <table class="table table-striped">
    <thead>
      <tr>
        <th ng-repeat="x in data">{{$index}}</th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="array in data">
        <td ng-repeat="item in array">
          {{item}} 
        </td>
      </tr> 
    </tbody>
  </table>    

</div>