Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 带有多个表达式和条件的$filter(';filter';)_Arrays_Angularjs_Filtering - Fatal编程技术网

Arrays 带有多个表达式和条件的$filter(';filter';)

Arrays 带有多个表达式和条件的$filter(';filter';),arrays,angularjs,filtering,Arrays,Angularjs,Filtering,好的。。。我正在为客户开发一个房地产页面,我需要一个过滤器,该过滤器根据用户选择的内容进行过滤,例如:租赁/购买/公寓/房子 目前这是我的功能 $scope.$watch('propfilters', function () { if( typeof $scope.propfilters != "undefined" ) { var filterstr = buildfilter($scope.propfilters); $scope.

好的。。。我正在为客户开发一个房地产页面,我需要一个过滤器,该过滤器根据用户选择的内容进行过滤,例如:租赁/购买/公寓/房子

目前这是我的功能

    $scope.$watch('propfilters', function () {

    if( typeof $scope.propfilters != "undefined" ) 
    {
        var filterstr = buildfilter($scope.propfilters);
        $scope.filteredtodos = $filter('filter')($scope.master, {Filters : filterstr});
        $scope.totallistings = $scope.filteredtodos.length;
    }
},true);
这是buildfilter

function buildfilter(str)
{
    var filt = [];
    var cty = '';
    var filter='';
    var i = 0;

    if (str.City !== false && typeof str.City != "undefined"){cty = '{city : "'+str.City+'"} && ';}
    if (str.Buy === true && typeof str.Buy != "undefined"){filt.push(" {Buy : true} ");i++;}
    if (str.Rent === true && typeof str.Rent != "undefined"){filt.push(" {Rent : true} ");i++;}
    if (str.OfferHouse === true && typeof str.OfferHouse != "undefined"){filt.push(" {OfferHouse : true} ");i++;}
    if (str.OfferApartment === true && typeof str.OfferApartment != "undefined"){filt.push(" {OfferApartment : true} ");i++;}
    var tmp = '';
    tmp = filt.join(" || ");
    filter = cty.concat(tmp);

    return filter;
}
这里是我的问题,当只选择一个过滤器时,它工作得很好,但当选择多个过滤器时,它会破坏
$filter('filter')
功能


但在这方面需要满足一些条件。。。如果设置了城市,则所有匹配项都必须在城市中,无论是租房还是买房(等),以及任何其他选项都可以为真,如果是,则显示。。我有一个805过滤器工作,但它是超过105行的代码。。。有什么想法吗?

所以你的过滤器不适用于多个选择,对吗?基本上,我尝试使用$filter(“filter”)根据值进行过滤,但我认为我可能需要更好的方法。因此,你在表中显示数据,对于每一列,你有一个过滤器,它将过滤列中的特定数据,对吗?显示器甚至还没有格式化,我正在尝试让过滤器删除与过滤器条件不匹配的数组对象