简体   繁体   中英

Angular display nested json value

Here is my data:

{
  "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."
          }
        }
      }
    ]
  }
}

And here is my HTML and 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>

My question is, how do I display the Value field nested in the Fields field?

I'm expecting:

  • date: September 22, 2015
  • rate: 10%
  • description: This rate is good as of the date listed above.
<ul>
  <li ng-repeat="item in data">
    {{ item.Name }}: {{ item.Fields["{3C3170EE-E6D5-4075-A864-8AB86D1E8E98}"].Value }}
  </li>
</ul>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM