我想在Angularjs中访问以下JSON的每个数据值。但我无法找到办法。假设我想访问以下查询的类型,名称,大小,单位。那么如何访问它,有人可以帮我解决这个问题吗?
{
"**openEHR-EHR-OBSERVATION.body_temperature.v1/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value**":{
"type": "DV_QUANTITY",
"name": "Temperature",
"serie":[
{
"magnitude": 34,
"units": "°C",
"date": "2016-12-28 13:23:32"
}
]
},
答案 0 :(得分:2)
你可以用ng-repeat做这样的事情
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = {
"openEHR-EHR-OBSERVATION.body_temperature.v1/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Temperature",
"serie":[
{
"magnitude": 34,
"units": "°C",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 34,
"units": "°C",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 38,
"units": "°C",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.blood_pressure.v1/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Systolic",
"serie":[
{
"magnitude": 4,
"units": "mm[Hg]",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 9,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 7,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.blood_pressure.v1/data[at0001]/events[at0006]/data[at0003]/items[at0005]/value":{
"type": "DV_QUANTITY",
"name": "Diastolic",
"serie":[
{
"magnitude": 6,
"units": "mm[Hg]",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 17,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 12,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.pulse.v1/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Rate",
"serie":[
{
"magnitude": 6,
"units": "/min",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 17,
"units": "/min",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 15,
"units": "/min",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.pulse.v1/data[at0002]/events[at0003]/data[at0001]/items[at0005]/value":{
"type": "DV_CODED_TEXT",
"name": "Regular?",
"serie":[
{
"code": "at0006at1028",
"value": "Regular",
"date": "2016-12-28 13:23:32"
},
{
"code": "at0006at1028",
"value": "Irregular",
"date": "2016-12-29 06:49:51"
},
{
"code": "at0006at1028",
"value": "Irregular",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.respiration.v1/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Rate",
"serie":[
{
"magnitude": 5,
"units": "/min",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 9,
"units": "/min",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 13,
"units": "/min",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.respiration.v1/data[at0001]/events[at0002]/data[at0003]/items[at0005]/value":{
"type": "DV_CODED_TEXT",
"name": "Rhythm",
"serie":[
{
"code": "at0006at0007",
"value": "Regular",
"date": "2016-12-28 13:23:32"
},
{
"code": "at0006at0007",
"value": "Regular",
"date": "2016-12-29 06:49:51"
}
]
}
}
});
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<div ng-repeat="(k,v) in name">
<p>{{v.type}}</p>
<p>{{v.name}}</p>
<span ng-repeat="x in v.serie">
magnitude: {{x.magnitude}},
units:{{x.units}},
date:{{x.date}}<br>
</span>
</div>
</body>
</html>
答案 1 :(得分:1)
工作演示:
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function($scope) {
$scope.jsonObj = {
"openEHR": {
"type": "DV_QUANTITY",
"name": "Temperature",
"serie": [{
"magnitude": 34,
"units": "°C",
"date": "2016-12-28 13:23:32"
}]
}
}
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
Type : {{jsonObj.openEHR.type}}<br>
Name : {{jsonObj.openEHR.name}}<br>
<div ng-repeat="item in jsonObj.openEHR.serie">
Magnitude : {{item.magnitude}}
</div>
</div>
&#13;
答案 2 :(得分:0)
似乎是EHRServer的查询结果。
“ serie”对象始终是与“ type”兼容的对象数组,因此您需要首先检查类型,以了解“ serie”对象中需要哪些字段。
对于类型= DV_QUANTITY,您将始终获得“幅度”和“单位”。当您“按路径分组”时,“日期”将始终存在。
您可以在官方文档https://cloudehrserver.com/learn
中找到更多信息顺便说一句,我是EHRServer的创建者。如果您有任何疑问,我们有一个社区支持聊天室https://gitter.im/CaboLabs/EHRServer