我是AngularJs的新手,我正在尝试使用angular.js和PHP制作网页。我在显示来自Json的数据时遇到了一些麻烦。 我的控制器
$scope.careprovider = function() {
$http.post('php/homefunctions.php', {
'act': 'careprovider'
}).success(function(data, status, headers, config) {
if (data.sessionError == 1) {
$location.path("/Login");
}else {
alert(data.careproviders);
$scope.careprovider = data.careproviders;
$scope.specializations = data.specializations;
}
}).error(function(data, status) {
$scope.errors.push(status);
});
}
我有JSON Array对象,如下所示
{"careproviders":
{"Anaesthesiologists":
[{"id":"37","addedBy":"5463e2dc0f","doctorName":"test","email":"sukalavan@consult-ic.com","hasUpdation":"NO"},
{"id":"38","addedBy":"62f5d33584","doctorName":"test1","email":"sukalavan@consult-ic.com","hasUpdation":"NO"}],
"Cardiologist":
{"id":"38","addedBy":"62f5d33584","doctorName":"test2","email":"sukalavan@consult-ic.com","hasUpdation":"NO"}]}
我想在angular.js中使用ng-repeat分别获取键和值。这是我的html
<div ng-repeat="f in careprovider">
<div class="cus-row-head">want show here the key</div>
<div class="row cus_row clearfix cus-sep-row posrel">
<div class="col-xs-12 col-md-12">
<div class="col-xs-6 col-lg-8 cus-col-mob-4">
<span class="cus-md-font">want to show here the doctor name</span>
<span class="cus-sm-font cus-inline">
<span class="glyphicon glyphicon-envelope"></span> email </span>
</div>
</div>
<a class="icons_sm icons-sm-edit"></a>
</div>
</div>
答案 0 :(得分:1)
答案 1 :(得分:0)
看看这个jsfiddle我把你想要的结构放在一起。
如果要遍历对象的键,则ng-repat应如下所示:
<div ng-repeat="key in keys(object)"></div>
在控制器中将键定义为:
$scope.keys = function(obj){return obj? Object.keys(obj) : [];}
(顺便说一下,你的json有一个缺失的&#39; [&#39;字符。)
答案 2 :(得分:0)
尝试这样做:
ng-repeat="(key, value) in data"
然后,您可以访问{{key}}和{{value}}
这里提到了这个方法:https://docs.angularjs.org/api/ng/directive/ngRepeat