我想从json响应中提取几个参数,但不知怎的,我无法填充它。我正在使用角度js和第三方api。 这是我的API结果。我只是想显示" [{"严重性":{"标签":"严重"},"标签":& #34; Skin Rash"}]"整个阵列。我需要在列表视图中填充html。
"过敏有一种或多种反应。每个反应都有严重性。 label严重是Severity对象中的一个键。标签Skin Rash在反应对象中。过敏对象有它自己的标签字段。"
{"反应":[{"严重性" {"标签":"重度"}"标签&# 34;:" Skin Rash"}]," audit":{" source":" medicalare"," createDate&#34 ;:" 2015-03-02T18:39:23Z"" updateDate":" 2015-03-02T18:39:23Z""&版本#34;:" 1"},"标签":"其他 - IODINE","结束":" 2007-10 -28T00:00:00-04:00""开始":" 1993-01-01T00:00:00-05:00""日期&# 34;:" 2015-03-02T18:37:42Z"}
答案 0 :(得分:-1)
使用ng-repeat:
不确定您在寻找什么,但这是一个例子:
修改
var app = angular.module("myApp", []);
app.controller("MyCtrl", function($scope){
var obj = {"reactions":[{
"severity":{"label":"Severe"},
"label":"Skin Rash"}],
"audit":{"source":"medicare","createDate":"2015-03-02T18:39:23Z",
"updateDate":"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"}
$scope.reactions = obj.reactions;
});
在index.html中;你可以做以下
<body ng-controller="MyCtrl">
<table class="table table-bordered">
<thead>
<th>Severity label</th>
<th>Just Label</th>
</thead>
<tbody>
<tr ng-repeat="item in reactions">
<td>{{item.severity.label}}</td>
<td>{{item.label}}</td>
</tr>
</tbody>
</table>
</body>
以下是Plunk:http://plnkr.co/edit/sgJ9RvtUYl6DkUDXPCc6?p=preview
答案 1 :(得分:-1)
这应该有效!
<强> HTML 强>
<div ng-controller="ctrl">
<div ng-repeat="item in data.reactions">
{{item.label}}
</div>
</div>
<强> JAVASCRIPT 强>
var myApp = angular.module('myApp', []);
myApp.controller('ctrl', function ($scope) {
$scope.data = {
"reactions":[
{
"severity":
{
"label":"Severe"
},
"label":"Skin Rash"
}
],
"audit":
{
"source":"medicare",
"createDate":"2015-03-02T18:39:23Z",
"updateDate":"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"
};
});
答案 2 :(得分:-1)
您可以尝试:
<ul ng-repeat="item in data.reactions">
{{item.label}}
</ul>