Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

javascript - json array disply in <li> using angular js

JSON array I am getting after get API call, I am getting following json response.

{
    "reactions":[{
        "severity":{
            "label":"Severe"
        },
        "label":"Skin Rash"
    }],
    "audit":{
        "source":"medicare",
        "createDate":"2015-03-02T18:39:23Z",
        "update??Date":"2015-03-02T18:39:23Z",
        "version":"1"
    },
    "label":"Other - IODINE",
    "ended":"2007-10-28T00:00:00-04:00",
    "started":"1993-01-01T00:00:00-05:00??",
    "date":"2015-03-02T18:37:42Z"
}". 

And I need to just display only

":[{"severity":{"label":"Severe"},"label":"Skin Rash"}]" in li tag. How can I do that ?

I need to populate this json array in <li> in html5. How can I do it? I am using restangular.:

Angular JS file:

Restangular.one('APIName', Parameter_to_api).get().then(function (result) {

  $scope.datalist= result;
}

HTML file

<ul class="links">
   <li ng-repeat="data in datalist"></li>                   
</ul>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try this

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

app.controller('firstCtrl', function($scope) {

  $scope.datalist = {
    data1: [2, 3, 4],
    data2: [6, 7, 8, ],
    data4: [9, 10, 12]
  }

});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body ng-app="app">
  <div ng-controller="firstCtrl">

    <ul class="links" ng-repeat="data in datalist">
      <li ng-repeat="i in data">{{i}}</li>
    </ul>

  </div>
</body>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...