如何在表中以json格式显示数组的值

时间:2016-10-19 12:15:23

标签: angularjs arrays json

我有var客户数组,我将响应存储在该数组中。现在我需要将值填充到表中,如果响应中存在intrstd

我无法理解。

JSON:

var customer = 
 [
  [
    {
      "businessuserid": 52,
      "businessusername": "Cars workshop",
      "businessusermobile": "9535000636",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": true,
      "emailvalidated": false,
      "email": "preethi@car.com",
      "upin": "000052"
    },
    {
      "businessuserid": 59,
      "businessusername": "MCF Business",
      "businessusermobile": "00",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": true,
      "emailvalidated": false,
      "email": "pavanhachholli@groupz.in",
      "upin": "000059"
    }
  ],
  [
    {
      "businessuserid": 44,
      "businessusername": "rk business New",
      "businessusermobile": "00",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": false,
      "emailvalidated": false,
      "email": "riteshnew@gmail.com",
      "upin": "000044"
    }
  ],
  [
    {
      "approved": true,
      "businessuserid": 43,
      "businessusername": "Cakey Bakes",
      "businessusermobile": "8050663763",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": true,
      "emailvalidated": false,
      "email": "preethi@groupz.com",
      "upin": "000043"
    }
  ],
  [
    {
      "intrsted": true,
      "attended": false,
      "businessuserid": 44,
      "businessusername": "rk business New",
      "businessusermobile": "00",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": false,
      "emailvalidated": false,
      "email": "riteshnew@gmail.com",
      "upin": "000044"
    }
  ],
  [
    {
      "intrsted": true,
      "attended": false,
      "businessuserid": 52,
      "businessusername": "Cars workshop",
      "businessusermobile": "9535000636",
      "businessusercountrycode": "91",
      "admin": true,
      "mobilevalidated": true,
      "emailvalidated": false,
      "email": "preethi@car.com",
      "upin": "000052"
    }
  ]

JS:

   $scope.userdetails = function(){
    for(var i=0;i<$scope.newuserlist[i].length;i++){


        for(var j=0;j<$scope.interested.length;j++){

               if($scope.interested[j].intrsted == undefined){
                        $scope.undefinedprogram = "null";
                    }
                    else if($scope.interested[j].intrsted == true){
                         $scope.users = $scope.interested[j].businessusername; 
            console.log($scope.users );
                        $scope.modalvalues.push($scope.users);
            console.log($scope.modalvalues);
                    }
        }
        }

};

如果我只能获取存在"intrsted":标记的数组值,我将能够相应地填充表中的值。

2 个答案:

答案 0 :(得分:1)

假设angularjs,因为你有angularjs标签。您可以使用ng-repeat循环浏览数据,并使用filter仅显示相关记录:

<table>
    <tr ng-repeat="item in your.controller.your.data | filter: { intrsted: true }">
        <td>{{item.businessusername}}</td>
        ...
    </tr>
</table>

但实际上,这是最基本的angularjs应用程序。您可以从任何初学者教程中获取此信息。

答案 1 :(得分:0)

试试这可能会对你有所帮助

var tbl=$("<table/>").attr("id","mytable");
    $("#div1").append(tbl);
    for(var i=0;i<customer.length;i++)
      {
         var tr="<tr>";
         var td1="<td>"+customer[i]["id"]+"</td>";
         var td2="<td>"+customer[i]["businessusername"]+"</td>";
         var td3="<td>"+customer[i]["businessusermobile"]+"</td></tr>";
         $("#mytable").append(tr+td1+td2+td3); 

    }