先进的滤镜阵列angularjs滤镜、阵列、先进、angularjs

2023-09-14 00:28:15 作者:称霸幼稚园

我试图执行与角过滤器的高级搜索。过滤器的想法是在阵列接收两个值(最大值和最小值)和复制是另一阵列的最大和最小范围内的所有时间间隔。

例如:阵列= {20,32,10,60,75,43,95}

最低:50最高分:100

合成矢量= {60,95} 75。

code:

 为(VAR I = 0; I< products.length;我++){        如果(产物[Ⅰ] preCIO方式> = $ scope.minimo&放大器;&放大器;产物[Ⅰ] preCIO&下; = $ scope.maximo)            返回this.products [I]    }    返回null;}; 

解决方案

是这样的:

  angular.filter('someFilter',函数(){    变种newArray = [];    返回功能(产品,最小,最大){        对于(VAR I = 0; I< products.length,我++){            如果(产品[I] preCIO方式> = min的放大器;服务和产品[I] preCIO< =最大值){                newArray.push(产品[I]);            }        }        返回newArray;    };}); 

和使用它像:< ...纳克重复=产品| someFilter:分:最大...>

PS制作阵列打孔效果

I'm trying to perform an advanced search with an angular filter. The idea of the filter is to receive two values (maximum and minimum) in an array and copy all intervals that are within the maximum and minimum of another array.

example: array = {20,32,10, 60, 75, 43, 95}

minimum: 50 maximum: 100

resultant vector = {60, 95} 75.

code:

 for (var i = 0; i < products.length; i++) {
        if (product[i].precio >= $scope.minimo && product[i].precio <= $scope.maximo)
            return this.products[i];
    }
    return null;
};

解决方案

Something like:

angular.filter('someFilter', function() {
    var newArray = [];
    return function(products, min, max) {
        for(var i = 0; i < products.length, i++) {
            if (products[i].precio >= min && products[i].precio <= max) {
                newArray.push(products[i]);
            }
        }
        return newArray;
    };
});

And use it like: <... ng-repeat="products | someFilter:min:max" ...>