【发布时间】:2016-12-22 20:50:17
【问题描述】:
我有 3 种类型的产品组:
- 导入(product_group_id 值 = 1)
- 导出(product_group_id 值 = 2)
- 非欧盟(product_group_id 值 = 3)
每个组都包含产品。我可以确定每个产品在我的产品创建中属于哪个产品组。
现在,我将这些产品汇总到产品索引中。我使用ng-repeat 执行此操作,并且我想根据 product_group_id 过滤产品,如下所示:
<div style="display: inline;" class="btn-group">
<a href="/products/export" type="submit"
class="{{ $product_group_id == 1 ? 'btn btn-primary' : 'btn btn-default' }}"
role="button">@lang('product.export')</a>
<a href="/products/import" type="submit"
class="{{ $product_group_id == 2 ? 'btn btn-primary' : 'btn btn-default' }}"
role="button">@lang('product.import')</a>
<a href="/products/non-eu" type="submit"
class="{{ $product_group_id == 3 ? 'btn btn-primary' : 'btn btn-default' }}"
role="button">@lang('product.non_eu')</a>
</div>
<table class="table table-hover product-table" ng-controller="ProductCtrl">
<thead>
<tr>
<th></th>
<th>#</th>
<th>@lang('product.name')</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="products in product | filter:SearchProduct" ng-cloak>
<td><input type="checkbox" name="product_id" class="checkbox"
value="@{{product.id}}"></td>
<td><a href="@{{ url('/products/' . product_id) }}">
@{{product.id}}</a></td>
<td><a ng-href="/products/@{{ product.id }}">
@{{product.name | uppercase}}</a></td>
</tr>
</tbody>
</table>
ProductService.js:
.controller('ProductCtrl', function($scope, $http) {
$http.get('/api/product')
.success(function(response) {
$scope.products = response;
});
});
我在控制器中将 product_group_id 设置为 1、2 和 3。
每次我创建一个新的$product 时,它都会显示在每个过滤器中(“/products/import”、“/products/export”和“/products/non-eu”)。
所以,我的问题是,如何在我的ng-repeat 中过滤我在$product_group_id 上的产品?
【问题讨论】:
-
你能发布“产品”的样本数据吗?还有你是如何获得“SearchProduct”变量的?
-
对于“SearchProduct”,我指的是我的搜索表单。
标签: angularjs filter laravel-5.3