dsfds656545 2014-11-13 15:04
浏览 48
已采纳

如何foreach angularjs php数组json输出

I'm new to AngularJs and i'm trying to make web with angular.js and PHP.I'm having some trouble on displaying data from a Json . My controller

 $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);
            });
        }

I have JSON Array object as shown below

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

I want to get the keys and values separately using ng-repeat in angular.js.Here is my 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>
  • 写回答

3条回答 默认 最新

  • dou448172583 2014-11-13 15:30
    关注

    Check out this jsfiddle I put together which has the type of structure you want.

    If you want to loop through the keys of an object, your ng-repat should look like this:

    <div ng-repeat="key in keys(object)"></div>
    

    Where keys is defined in your controller as:

    $scope.keys = function(obj){return obj? Object.keys(obj) : [];}
    

    (BTW, your json has a missing '[' character in it.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制