我在應用程序中使用Angular。所有ID的AngularJS ng-repeat
我是從我的數據庫獲取數據在陣列狀的物品:
$ordersall[$count] = array(
"orderID" => $looporders["orderID"],
"customerID" => $looporders["customerID"],
"customerName" => $customerName,
"orderDate" => $looporders["orderDate"],
"orderDeliveryDate" => $looporders["orderDeliveryDate"],
"orderStatus" => $looporders["orderStatus"],
"orderdetailID" => $row["orderdetailID"],
"productTitle" => $productTitle,
"productPrijs" => $productPrijs,
"aantal" => $row["orderdetailAantal"],
"extras" => "",
"extrasprice" => ""
);
現在我想打印出這個數據對於每個ORDERID,每ORDERID我想顯示:客戶名稱,orderDate存儲和orderdetails喜歡產品,價格,臨時演員...等。但一個訂單ID(例如:5)可以有多個orderdetails,所以多個產品的名稱,價格,額外等
當我只有一個orderID我解決了它像這樣:
Angular
app = angular.module('app', []);
app.controller("NavCtrl",function($scope,$http){
var serviceBase = 'api/';
$http.get(serviceBase + 'orderoverview/58').then(function (results) {
$scope.categories = results.data;
$scope.getTotal = function(){
var total = 0;
for(var i = 0; i < $scope.categories.length; i++){
var categories = $scope.categories[i];
total += (categories.productPrice * categories.orderdetailAantal);
if(categories.extra1 != "")
{
total += categories.extrasPrice;
}
}
return total;
}
});
});
HTML
<div class="col-md-3" ng-controller="NavCtrl">
<div class="sm-st clearfix">
<!--<span class="sm-st-icon st-red"><i class="fa fa-check-square-o"></i></span>-->
<div class="sm-st-info">
<i class="fa fa-square"></i>
<span>Sander Hofman</span>
<p>1 minutes</p>
<ul>
<li ng-repeat= "p in categories" ng-hide="categories.extra1.length">
{{p.orderdetailAantal}} {{p.productTitle}} <br>
+ {{p.extra1}} {{p.extra2}} {{p.extra3}} {{p.extra4}}
</li>
<li class="divider"></li>
</ul>
<p class="totalprice">{{ getTotal() }} euro</p>
</div>
</div>
</div>
但是現在我如何能做到在HTML中我有一個列表項,每單編號及其所有ORDERDETAILS的?
例如:
的orderID:5
orderdetail1:productTitle,價格,數量
orderdetail2:productTitle,價格,數量
orderdetail2:productTitle,價格,數量
orderID6:
orderdetail1:productTitle,價格,數量
JSON樣品
[{"orderID":4,"customerID":1,"customerName":"Sander Hofman","orderDate":"2015-04-20 09:49:06","orderDeliveryDate":"2015-04-20","orderStatus":"done","orderdetailID":2,"productTitle":"Sexy Teacher","productPrijs":4,"aantal":1,"extras":"","extrasprice":""},
{"orderID":5,"customerID":2,"customerName":"Jelle Hofman","orderDate":"2015-04-20 12:05:09","orderDeliveryDate":"2015-04-20","orderStatus":"prepare","orderdetailID":3,"productTitle":"The Coach","productPrijs":3,"aantal":1,"extras":"","extrasprice":""},
{"orderID":5,"customerID":2,"customerName":"Jelle Hofman","orderDate":"2015-04-20 12:05:09","orderDeliveryDate":"2015-04-20","orderStatus":"prepare","orderdetailID":4,"productTitle":"The Virgin","productPrijs":3.2,"aantal":1,"extras":"","extrasprice":""},
{"orderID":5,"customerID":2,"customerName":"Jelle Hofman","orderDate":"2015-04-20 12:05:09","orderDeliveryDate":"2015-04-20","orderStatus":"prepare","orderdetailID":5,"productTitle":"Sexy Teacher","productPrijs":4,"aantal":3,"extras":"","extrasprice":""},
{"orderID":22,"customerID":11,"customerName":"Tom Welslau","orderDate":"2015-04-20 14:15:12","orderDeliveryDate":"2015-04-20","orderStatus":"prepare","orderdetailID":22,"productTitle":"The Virgin","productPrijs":3.2,"aantal":1,"extras":"","extrasprice":""},
{"orderID":22,"customerID":11,"customerName":"Tom Welslau","orderDate":"2015-04-20 14:15:12","orderDeliveryDate":"2015-04-20","orderStatus":"prepare","orderdetailID":23,"productTitle":"The Virgin","productPrijs":3.2,"aantal":1,"extras":"","extrasprice":""}
你可以添加一些示例JSON?你想要使用'angular.forEach' –
按要求編輯 – Sesamzaad