AngularJS自定义过滤器在ng-repeat条件下

时间:2016-04-05 14:35:54

标签: angularjs laravel laravel-5.1

我正在努力掌握如何制作自定义过滤器。我正在寻找从下拉列表中按ItemID过滤的功能。这工作正常,但如果类型值为8,我需要它停止过滤。这是因为我更改了item_typeID不存在的数据集

我当前的代码

<ul ng-repeat="(key, item) in stock | filter: {item_code: searchCode} | filter: {item_name: searchName} | filter: {productID: product} | filter: {companyID: company} |  filter: { item_typeID: type } ">

    <li ng-show="stock_items" >
        <div>Product</div>
        {[{ item.product_name }]}
    </li>
    <li ng-show="stock_items" >
        <div>Item Name</div>
            <a ng-click="openModal(item.itemID)" class="activate_modal" name="modal_window">{[{ item.item_name }]}</a>
    </li>

    <li ng-show="stock_items">
        <div>Item Code</div>
        {[{ item.item_code }]}

    </li>

    <li ng-show="stock_items" >
        <div>Stock level</div>
        {[{ item.total_stock }]}
    </li>

    <li ng-show="stock_items">

        <button ng-click="addItem(item.itemID, key)" ng-disabled="disable_them[key]" style="width:100%;" class="btn-icon add-to-cart">Add</button>

    </li>

只是为了让你知道我已经改变标准{{tags to {[{以便我可以在Laravel中使用Blade模板

1 个答案:

答案 0 :(得分:0)

我更改了过滤行以包含此

<ul ng-repeat="(key, item) in stock | filter: {item_code: searchCode} | filter: {item_name: searchName} | filter: {productID: product} | filter: {companyID: company} |  filter: typeFilter ">

这包括新过滤器&#34; typeFilter&#34;然后在Javascript中添加了以下范围函数

$scope.typeFilter = function (type) {
        if($scope.type == undefined || $scope.type == "") {
          return true;
        } else if(type.item_typeID == $scope.type){
          return true;
        } else if($scope.type == 8) {
            return true;
        } else {
          return false;
        }
    }