如何为我的HTML表格下面的cloudant嵌套循环响应写Ng-repeat ...?

时间:2017-06-05 20:04:26

标签: javascript angularjs cloudant



//<!--  here is the sample cloudant response we have in that need to filter below docs  -->
    {  
       "data":{  
          "total_rows":3,
          "offset":0,
          "rows":[  
             {  
                "id":"093b21d31878c8cbed02b89ea020c988",
                "key":"093b21d31878c8cbed02b89ea020c988",
                "value":{  },
 <!-- Here we have docs response need to filter -->
                "doc":{  
                   "_id":"093b21d31878c8cbed02b89ea020c988",
                   "_rev":"1-29e2996bce09fd8fcf826871b325302f",
                   "slot":"1",
                   "out_time_stamp":"none",
                   "color":"red",
                   "s.no":35,
                   "vehicle_make":"audi",
                   "vehicle_Make_Model":"Audi A5",
                   "number_plate":"1AU890",
                   "type":"bike",
                   "In_time_stamp":"2-25-21"
                }
             },
             {  },
             {  }
          ]
       },
       "status":200,
       "config":{  
          "method":"GET",
          "transformRequest":[  
             null
          ],
          "transformResponse":[  
             null
          ],
          "username":"****",
          "password":"*****",
          "url":"https://####.cloudant.com/parking_logs/_all_docs?include_docs=true&conflicts=true",
          "headers":{  
             "Accept":"application/json, text/plain, */*"
          },
          "cached":false
       },
       "statusText":"OK"
    }
&#13;
<!--sample html table --!>
      <table class="table table-no-border m-0">
                                      </thead>
                                        <tr style="color:#232527;">
                                          <th> #No </th>
                                          <th> Vehicle Type </th>
                                          <th> Vehicle Model </th>
                                          <th> Vehicle color </th>
                                          <th> Vehicle Number</th>
    									  <th> Level</th>
                                          <th> Slot Occupied</th>
    									  <th> In Time Stamp </th>
    									  <th> Out Time Stamp </th>
                                        </tr>
    									</thead>
    									 <tbody>
                                        <tr ng-repeat="x in records">
                                          <td >{{ x.sno}}</td>
                                          <td> {{x.type}} </td>
    									  <td> {{ x.vehicle_make}} </td>
                                          <td> {{x.color}}</td>
                                          <td> {{x.number_plate}}</td>
                                          <td>{{x.vehicle_Make_Model}}</td>
                                          <td> {{x.slot}}</td>
    									  <td> {{x.In_time_stamp}}</td>
    									  <td> {{x.out_time_stamp}}</td>
                                        </tr>
    									 </tbody>
                       </table>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

解析承诺后,从响应中提取行。像这样:

.....function(success) {
$scope.records = success.data.rows;
.......

在您的模板中迭代记录并绑定值。,在

下面
<tr ng-repeat="x in records">
  <td >{{ x.doc.sno }}</td>
   .........
  <td> {{ x.doc.color }}</td>

这可以解决您的问题。如果它不起作用,请告诉我