根据循环

时间:2016-04-19 08:56:13

标签: angularjs

我想要下订单的所有商品,如下所示: enter image description here

但是我在一个订单中获得所有订单的所有项目,如下所示:

enter image description here

以下是我的html代码:

<div class="container"  data-ng-init="getorders()">
<div id="orderDiv" ng-repeat="orderrecords in orderdata">   
      <h5>Order ID: {{orderrecords.order_no}}</h5>
      <h6><i class="fa fa-calendar"></i> Order Date: {{orderrecords.date_purchased}}</h6>
    </div>   
  </div>
  <div class="order-grid-body" data-ng-init="getorderdetails(orderrecords.order_id,'')"> 
    <table class="table table-bordered orders">    
      <tr ng-repeat="ordrdatadesc in orderdatadesc">
        <td>{{ordrdatadesc.product_name}}
</td>
</tr>
</table>

以下是我的控制器代码:

angular.module('nshop').controller("orderController",['$scope','$localStorage','$http',function($scope,$localStorage,$http){
    var noorder="You have not placed any orders";
    var userid= $localStorage.user_id;
    $scope.noorder="";
    $scope.getorders=function(){
        var formData = {
        'userid':userid,
        }; 
        $http({
          method  : 'POST',
          url     : 'rest/getUserOrders',
          data    : formData
         })
        .success(function(data) { 
        if(data[0].status==1){                   
             $scope.orderdata=data;
        }
        else{
        $scope.noorder=noorder; 
        }
        })      
    }
    $scope.getorderdetails=function(orderid,status){
    $scope.orderdatadesc="";        
        var formData = {
        'orderid':orderid,
        'status':status,
        }; 
        $http({
          method  : 'POST',
          url     : 'rest/getUserOrdersdetail',
          data    : formData
         })
        .success(function(data) {
            $scope.orderdatadesc=data;
        })
        .error(function(data){
            console.log('error');
        });
    }
}]);

0 个答案:

没有答案