我在应用程序中使用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