繁体   English   中英

AngularJS:多个自定义过滤器/搜索

[英]AngularJS: Multiple Custom filter/search

我一直在研究使用AngularJS的学位课程查找工具。 我正在尝试构建的是电子商务样式的边栏过滤选项。 我已经获得了“学位级别”和一个自由格式的搜索字段,但我无法使“提供的地点信息”过滤器与单选按钮一起使用。

这是我的控制器:

    $scope.search = function (row) {
    return (
        angular.lowercase(row.DPNAME).indexOf(angular.lowercase($scope.query) || '') !== -1 ||
        angular.lowercase(row.DPCAREERS).indexOf(angular.lowercase($scope.query) || '') !== -1 ||
        angular.lowercase(row.DPCONCENTRATIONS).indexOf(angular.lowercase($scope.query) || '') !== -1
    );
};
$scope.DLsearch = function (row) {
    return (
        row.DPDEGREELEVEL.indexOf($scope.qDegreeLevel || '') !== -1
    );
};

$scope.LOCsearch = function (row) {
    return (
        row.DPONCAMPUSMESA == 'Yes'
    );
};

而且它的最后一个过滤器运行不正常。 如果将“ DPONCAMPUSMESA”替换为任何其他位置字段(例如DPONCAMPUSLISLE或DPNONTRADNMCALCENTRALIL),它将正确过滤数据。 但是我无法将其连接到单选按钮。

我对过滤器也持不同态度。

这是我一直在使用的CodePen: http ://codepen.io/ksherman/pen/yYqGgx?editors=101如果您对JSON结构感兴趣: http : //www.jsoneditoronline.org/? id = 5145f3cca9dd9d5e5eaef2e39e2b2808

我已打开您的CodePen,最后一个过滤器的工作方式与写入完全相同-仅保留了满足条件的两行(row.DPONCAMPUSMESA =='是')。 要使其更通用,请尝试:

$scope.LOCsearch = function (row) {
    if (!$scope.qLocation) {
        return true; // no filter or 'All' option
    } else {
        return row[$scope.qLocation] == 'Yes';
    }
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM