我有这个json数据:

     {
status: "SUCCESS",
data: [
{
FirstName: "Student ",
LastName: "1",
Id: 1,
ObjectState: 0
},
{
FirstName: "Student ",
LastName: "2",
Id: 2,
ObjectState: 0
    }
   }
  ]
}


我已经在控制器和视图中尝试过这样的操作:
app.js:

.controller("etudCtrl",["$scope", "$http", function ($scope, $http) {
        var i;

    $http({method: 'GET', url: 'MyURL'})
             .success(function (data) {

                for(i=0;i<data.length;i++){
                $scope.paged = data[i].data; // response data
                console.log($scope.paged+" $scope.paged");
        }
            $scope.currentPageStores= $scope.paged;
            console.log($scope.currentPageStores+"  values");

              console.log("success");
    }).error(function (data, status, headers, config) {
              console.log("data error ...");
     });
 }])


Students.html:

<table>
<thead>...</thead>
 <tbody data-ng-controller="etudCtrl">
   <tr ng-repeat="store in currentPageStores" >
  <td align="center">{{store.LastName}}</td>
  <td align="center">{{store.FirstName}}</td>
  </tr>
</tbody>
</table>


这是我在控制台中得到的:

values
success


我没有在控制台或表格中得到任何数据:(
任何帮助请
谢谢

更新:
我尝试这样:

 $rootScope.usersData = angular.toJson(data.data);
 console.log($rootScope.usersData+" my data");


我得到了要显示在控制台中的所有数据

更新2:

 $http({method: 'GET', url: 'MyURL'})
             .success(function (data) {

       console.log(JSON.stringify(data)+"myData");

        for(i=0;i<data.length;i++){
        $scope.paged = data.data[i]; // response data
        console.log($scope.paged+" $scope.paged");
              }
.....
}


我在控制台中得到这个:

{"status":"SUCCESS","data":[{"FirstName":"Student ","LastName":"1","Id":1,"ObjectState":0},{"FirstName":"Student ","LastName":"2","Id":2,"ObjectState":0}]}myData

最佳答案

无需在控制器中循环。请尝试以下操作:

您的控制器:

.controller("etudCtrl",["$scope", "$http", function ($scope, $http) {


    $http({method: 'GET', url: 'MyURL'})
             .success(function (data) {
            $scope.currentPageStores= data.data;
            console.log($scope.currentPageStores+ "  values");

              console.log("success");
    }).error(function (data, status, headers, config) {
              console.log("data error ...");
     });
 }])


您的student.html

<table>
<thead>...</thead>
 <tbody data-ng-controller="etudCtrl">
   <tr ng-repeat="store in currentPageStores track by $index" >
  <td align="center">{{store.LastName}}</td>
  <td align="center">{{store.FirstName}}</td>
</tbody>
</table>


这是一个PLUNKER示例,说明如何以数组形式访问数据:http://plnkr.co/edit/Q9ewbH7XevsOQG0Yzv6B?p=preview

10-08 06:16
查看更多