过滤器对象匹配的细节 [英] filter objects matching details

查看:122
本文介绍了过滤器对象匹配的细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

功能正常工作,他们通过酒吧code和过滤制造商的库存。我想让它像默认angularjs过滤。如果让我选择制造商 - LG和酒吧code - 112,如果它们不匹配,那么它应该不显示任何内容。

但现在分开显示,当我点击过滤功能它过滤棒code时过滤器2功能的过滤器制造商

  $ scope.filter =功能(巴code){
            变种过滤= [];
            对于(VAR I = 0; I< $ scope.inventories.length;我++){
                如果($ scope.inventories [I]的.bar code ==酒吧code){
                    filtered.push($ scope.inventories [I]);
                }
            }
            $ scope.filtered_inventories =过滤;
        };        $ scope.filter2 =功能(制造商){
            变种过滤= [];
            对于(VAR I = 0; I< $ scope.inventories.length;我++){
                如果($ scope.inventories [I] .manufacturer ==制造商){
                    filtered.push($ scope.inventories [I]);
                }
            }
            $ scope.filtered_inventories =过滤;
        };


解决方案

试试这个

  $ scope.filter =功能(巴code,制造商){
        变种过滤= [];
        对于(VAR I = 0; I< $ scope.inventories.length;我++){
            如果($ scope.inventories [I]的.bar code ==酒吧code $ || scope.inventories [I] .manufacturer ==制造商){
                filtered.push($ scope.inventories [I]);
            }
        }
        $ scope.filtered_inventories =过滤;
    };

Functions works fine, they filter inventory by barcode, and manufacturer. I want to make it like default angularjs filtering. If I choose manufacturer - LG and barcode - 112 and if they don't match, then it shouldn't display anything.

But for now it displays separately, when i click on filter function it filters barcode when on filter2 function filter manufacturer

$scope.filter = function(barcode) {
            var filtered = [];
            for(var i = 0; i < $scope.inventories.length; i++){
                if($scope.inventories[i].barcode == barcode){
                    filtered.push($scope.inventories[i]);
                } 
            }
            $scope.filtered_inventories = filtered;
        };

        $scope.filter2 = function(manufacturer) {
            var filtered = [];
            for(var i = 0; i < $scope.inventories.length; i++){
                if($scope.inventories[i].manufacturer == manufacturer){
                    filtered.push($scope.inventories[i]);
                } 
            }
            $scope.filtered_inventories = filtered;
        };

解决方案

Try this

    $scope.filter = function (barcode, manufacturer) {
        var filtered = [];
        for(var i = 0; i < $scope.inventories.length; i++){
            if($scope.inventories[i].barcode == barcode || $scope.inventories[i].manufacturer == manufacturer){
                filtered.push($scope.inventories[i]);
            } 
        }
        $scope.filtered_inventories = filtered;
    };

这篇关于过滤器对象匹配的细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆