其他ng-repeat中的ng-repeat不起作用

时间:2016-09-03 07:36:22

标签: angularjs

{
  "data": {
    "name": "NAME",
    "tests": [
      {
        "testname": "abc",
        "relatedResource": [
          {
            "accessType": "fttb",
          },
          {
            "accessType": "fttn",
          }
        ]
      },
      {
        "testname": "xyz",
        "relatedResource": [
          {
            "accessType": "fttp",
          },
          {
            "accessType": "fttp",
          }
        ]
      }
    ]
  }
}

控制器

$scope.data=response.data.tests;  

<div ng-repeat="l in data">
    <div ng-repeat="i in l.relatedResource">
        {{i.accessType}}
   </div>
</div>

3 个答案:

答案 0 :(得分:0)

试试这个,您需要多个ng-repeat才能访问relatedResource

here我打印输出

    <div ng-controller="MyCtrl">
  <div ng-repeat="(key,val) in data">
  {{val.name}}
      <div ng-repeat="test in val.tests">
                    - {{test.testname}}
           <div ng-repeat="resource in test.relatedResource">
                    - -{{resource.accessType}}
           </div>
      </div>
</div>
</div>

答案 1 :(得分:0)

试试这个代码段

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.data = {
  "data": {
    "name": "NAME",
    "tests": [
      {
        "testname": "abc",
        "relatedResource": [
          {
            "accessType": "fttb",
          },
          {
            "accessType": "fttn",
          }
        ]
      },
      {
        "testname": "xyz",
        "relatedResource": [
          {
            "accessType": "fttp",
          },
          {
            "accessType": "fttp",
          }
        ]
      }
    ]
  }
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <div ng-repeat="obj in data">
    <span ng-repeat="val in obj.tests">
      {{val.testname}}
      <span ng-repeat="v in val.relatedResource">
        {{v.accessType}}
      </span>
      <br/>
    </span>
  </div>
</div>
  

答案 2 :(得分:0)

实际上关于这个问题的信息并不多。

如果从远程服务器收到json数据,则应始终检查并将其转换为真正的json对象。

您只需使用

即可
$scope.data = response.data.tests;

$scope.getData = function() 
{
   return angular.toJson($scope.data);
}

或者您可以使用以下方法进行测试:

{{data | json}}