Angular显示嵌套的json值

时间:2015-08-25 20:51:13

标签: javascript json angularjs

这是我的数据:

{
  "statusCode": 200,
  "result": {
    "items": [
      {
        "Name": "date",
        "Fields": {
          "{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}": {
            "Name": "Promo Content",
            "Value": "September 22, 2015"
          }
        }
      },
      {
        "Name": "rate",
        "Fields": {
          "{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}": {
            "Name": "Promo Content",
            "Value": "10%"
          }
        }
      },
      {
        "Name": "description",
        "Fields": {
          "{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}": {
            "Name": "Promo Content",
            "Value": "This rate is good as of the date listed above."
          }
        }
      }
    ]
  }
}

这是我的HTML和JS:

<body ng-app="myApp">

<div ng-controller="CallWebApi">
    <ul>
        <li ng-repeat="items in data">
            {{ items.Name }}: {{ items.Fields }}
        </li>
    </ul>
</div>
<script>
angular.module('myApp',[]).controller('CallWebApi', function($scope, $http) {
    // Local version of the data
    $http.get('./test.js').

        success(function (data) {
            $scope.data = data.result.items;
            console.log('success ' + data)
        })
        .error(function(data) {
            console.log('failure ' + data)
        });
});
</script>
</body>

我的问题是,如何显示嵌套在“字段”字段中的“值”字段?

我期待:

  • 日期:2015年9月22日
  • 率:10%
  • description:此费率自上述日期起是好的。

1 个答案:

答案 0 :(得分:0)

<ul>
  <li ng-repeat="item in data">
    {{ item.Name }}: {{ item.Fields["{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}"].Value }}
  </li>
</ul>