为ng-repeat

时间:2017-11-08 12:00:13

标签: javascript html angularjs filtering prestashop

我试图在ng-repeat中创建一个过滤器。我想要实现的是一个列表 - >有关按钮单击组合的更多信息。我使用prestashop webservice来检索数据。所有数据都来自json对象。

所以我确实在堆栈上尝试了一些其他的解决方案,但遗憾的是那些对我不起作用。请参阅以下示例:

所以我的html存在2个块。一个是所有订单的列表,很快按ID,日期和总付款金额汇总。另一个块将是更多信息部分。本节将显示订购的产品,日期等等。

所以我创建了列表,并通过添加ng-click使div(每个列表项)成为可点击元素。 (是的,我也尝试了<button ng-click="function()">但是因为它没有使用div或我选择用于div(布局)的按钮之间的任何区别。

因此onclick事件会抓取order.id并将其添加到过滤器中。然后将此过滤器应用于第二个&#34;更多信息&#34;块。然后,此块应过滤此ID并仅捕获该信息。但是,由于这部分我仍然无法工作,因此我已经陷入困境。所以我到目前为止所尝试的内容如下所示:

我的HTML

&#13;
&#13;
var myApp = angular.module('myApp',['ngRoute','cgNotify','pascalprecht.translate','ngCookies','ngSanitize']);


// Orders
myApp.controller('OrderController', function($scope, $http){
    $http.get('config/get/getOrders.php').then(function(response){
        $scope.orders = response.data.orders.order
    });
    $scope.currentOrder = {
        "id": 3
    };
    console.log($scope.currentOrder);
    $scope.showOrder = function(order) {
		var order_id = order.id;

        $scope.currentOrder = {
			"id": parseInt(order_id)
        };

        console.log($scope.currentOrder);
        return $scope.currentOrder;
    }
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!-- The list -->
<div class="col-lg-12" ng-controller="OrderController">
	<div class="container">
		<form class="defaultinput col-xl-5 col-lg-6 col-md-8 d-flex justify-content-start">
			<svg class="align-self-center d-flex" height="20px" version="1.1" viewbox="7 5 20 20" width="20px" xmlns="http://www.w3.org/2000/svg">
			<defs></defs>
			<path d="M27,23.5376923 L20.7969231,17.3046154 C21.7538462,16.0192308 22.3276923,14.4292308 22.3276923,12.7007692 C22.3276923,8.44769231 18.8969231,5 14.6638462,5 C10.4307692,5 7,8.44769231 7,12.7007692 C7,16.9538462 10.4307692,20.4015385 14.6638462,20.4015385 C16.4084615,20.4015385 18.0123077,19.8092308 19.3,18.8223077 L25.4476923,25 L27,23.5376923 L27,23.5376923 Z M8.35846154,12.7007692 C8.35846154,9.20692308 11.1869231,6.36461538 14.6638462,6.36461538 C18.1407692,6.36461538 20.9692308,9.20692308 20.9692308,12.7007692 C20.9692308,16.1946154 18.1407692,19.0369231 14.6638462,19.0369231 C11.1869231,19.0369231 8.35846154,16.1946154 8.35846154,12.7007692 L8.35846154,12.7007692 Z" fill="#8E8E93" fill-rule="evenodd" id="Search-Icon" stroke="none"></path></svg>
			<input class="form-control" placeholder="{{ 'Zoeken' | translate }}" type="text">
		</form>
		<div class="row listrow" ng-repeat="order in orders">
			<div ng-click="showOrder(order)" class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
				<div class="col-lg-3">
					<p type="number" ng-bind="order.id" ng-value="order.id"></p>
				</div>
				<div class="col-lg-4">
					<p ng-bind="order.invoice_date"></p>
				</div>
				<div class="col-lg-5">
					<p ng-bind="order.total_paid_real"></p>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- The more information block -->

<div class="col-lg-11" ng-controller="OrderController">
	<div>
		<div ng-repeat="order in orders | filter: currentOrder" class="text-center margin-t-10">
			<div class="row listrow"></div>
			<h1>{{ 'Totaal' | translate }}</h1><h1 ng-bind="order.id"></h1>
			<h3>#010 - {{ 'Contant' | translate }} {{ 'Betaald' | translate }}</h3>
		</div>
		<div class="row listrow margin-t-20 no-border">
			<div class="col-6">
				Blauw shirt - Maat: L
			</div>
			<div class="col-1">
				2x
			</div>
			<div class="col-5 text-right">
				€ 200,00
			</div>
		</div>
		<div class="row listrow no-border">
			<div class="col-6">
				Blauw shirt - Maat: L
			</div>
			<div class="col-1">
				2x
			</div>
			<div class="col-5 text-right">
				€ 200,00
			</div>
		</div>
		<div class="row margin-t-30 justify-content-end">
			<div class="col-6">
				<div class="row">
					<div class="col-6">
						{{ 'Subtotaal' | translate }}
					</div>
					<div class="col-6 text-right">
						€ 400,00
					</div>
				</div>
				<div class="row listrow">
					<div class="col-6">
						21% {{ 'BTW' | translate }}
					</div>
					<div class="col-6 text-right">
						€ 84,00
					</div>
				</div>
				<div class="row">
					<div class="col-5 padding-r-5">
						{{ 'Totaal' | translate }}
					</div>
					<div class="col-3 align-self-center no-padding">
						<h6>(2 items)</h6>
					</div>
					<div class="col-4 padding-l-0 text-right">
						€ 484,00
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="row margin-t-100 d-flex justify-content-around">
		<button ng-click="" type="button" class="smallbutton defaultbutton">{{ 'Print bon' | translate }}</button>
		<a href="#/refund">
		<button type="button" class="smallbutton defaultbutton">{{ 'Retour' | translate }}</button>
		</a>
	</div>
</div>
&#13;
&#13;
&#13;

JSON示例

{"orders":{"order":[{"id":"1","id_address_delivery":"4","id_address_invoice":"4","id_cart":"1","id_currency":"1","id_lang":"1","id_customer":"1","id_carrier":"2","current_state":"5","module":"ps_checkpayment","invoice_number":"4","invoice_date":"2017-03-16 15:18:27","delivery_number":"4","delivery_date":"2017-03-16 15:18:27","valid":"1","date_add":"2017-03-16 14:36:24","date_upd":"2017-03-16 15:18:27","shipping_number":{"@attributes":{"notFilterable":"true"}},"id_shop_group":"1","id_shop":"1","secure_key":"b44a6d9efd7a0076a0fbce6b15eaf3b1","payment":"Payment by check","recyclable":"0","gift":"0","gift_message":{},"mobile_theme":"0","total_discounts":"0.000000","total_discounts_tax_incl":"0.000000","total_discounts_tax_excl":"0.000000","total_paid":"55.000000","total_paid_tax_incl":"55.000000","total_paid_tax_excl":"55.000000","total_paid_real":"55.000000","total_products":"53.000000","total_products_wt":"53.000000","total_shipping":"2.000000","total_shipping_tax_incl":"2.000000","total_shipping_tax_excl":"2.000000","carrier_tax_rate":"0.000","total_wrapping":"0.000000","total_wrapping_tax_incl":"0.000000","total_wrapping_tax_excl":"0.000000","round_mode":"0","round_type":"0","conversion_rate":"1.000000","reference":"XKBKNABJK","associations":{"order_rows":{"@attributes":{"nodeType":"order_row","virtualEntity":"true"},"order_row":[{"id":"1","product_id":"2","product_attribute_id":"10","product_quantity":"1","product_name":"Blouse - Color : White, Size : M","product_reference":"demo_2","product_ean13":{},"product_isbn":{},"product_upc":{},"product_price":"26.999852","unit_price_tax_incl":"27.000000","unit_price_tax_excl":"27.000000"},{"id":"2","product_id":"3","product_attribute_id":"13","product_quantity":"1","product_name":"Printed Dress - Color : Orange, Size : S","product_reference":"demo_3","product_ean13":{},"product_isbn":{},"product_upc":{},"product_price":"25.999852","unit_price_tax_incl":"26.000000","unit_price_tax_excl":"26.000000"}]}}},{"id":"2","id_address_delivery":"4","id_address_invoice":"4","id_cart":"2","id_currency":"1","id_lang":"1","id_customer":"1","id_carrier":"2","current_state":"5","module":"ps_checkpayment","invoice_number":"3","invoice_date":"2017-03-16 15:18:27","delivery_number":"3","delivery_date":"2017-03-16 15:18:27","valid":"1","date_add":"2017-03-16 14:36:24","date_upd":"2017-03-16 15:18:27","shipping_number":{"@attributes":{"notFilterable":"true"}},"id_shop_group":"1","id_shop":"1","secure_key":"b44a6d9efd7a0076a0fbce6b15eaf3b1","payment":"Payment by check","recyclable":"0","gift":"0","gift_message":{},"mobile_theme":"0","total_discounts":"0.000000","total_discounts_tax_incl":"0.000000","total_discounts_tax_excl":"0.000000","total_paid":"75.900000","total_paid_tax_incl":"75.900000","total_paid_tax_excl":"75.900000","total_paid_real":"75.900000","total_products":"73.900000","total_products_wt":"73.900000","total_shipping":"2.000000","total_shipping_tax_incl":"2.000000","total_shipping_tax_excl":"2.000000","carrier_tax_rate":"0.000","total_wrapping":"0.000000","total_wrapping_tax_incl":"0.000000","total_wrapping_tax_excl":"0.000000","round_mode":"0","round_type":"0","conversion_rate":"1.000000","reference":"OHSATSERP","associations":{"order_rows":{"@attributes":{"nodeType":"order_row","virtualEntity":"true"},"order_row":[{"id":"3","product_id":"2","product_attribute_id":"10","product_quantity":"1","product_name":"Blouse - Color : White, Size : M","product_reference":"demo_2","product_ean13":{},"product_isbn":{},"product_upc":{},"product_price":"26.999852","unit_price_tax_incl":"27.000000","unit_price_tax_excl":"27.000000"}

为了方便起见,我还创建了JSfiddle

所以我的问题是,因为第一组过滤器正在工作(3)。为什么我的点击功能不起作用?使用console.log()我检查了id是否被选中了。那么为什么过滤器没有更新?

如果您有任何疑问,请将其作为评论。

一如既往,提前致谢!

0 个答案:

没有答案
相关问题