【问题标题】:AngularJS always including an object in an ngRepeat filterAngularJS 总是在 ngRepeat 过滤器中包含一个对象
【发布时间】:2016-05-15 20:44:03
【问题描述】:

我希望始终包含具有特定属性值的某些对象,而不管活动过滤器如何。

示例说明:我正在按“状态:生产”进行过滤,这将仅列出状态为生产的员工。我编辑一个条目并保存它,该对象现在将saving 属性设置为true。如果我将过滤器更改为status: Offboarded,该条目现在将被过滤掉。我想不过滤任何具有saving: true 属性的对象。

过滤器示例:

<tr ng-repeat="employee in employeeData | filter:{status: queries.status}
                                        | filter:{duties: queries.duties}
                                        | filter:queries.generalQuery">

我想始终包含employeesaving 属性为true 的任何employee。我该怎么做?

【问题讨论】:

    标签: angularjs filter


    【解决方案1】:

    你可以用一个过滤函数来做到这一点。

    <tr ng-repeat="employee in employeeData | filter: filterEmployees">
    

    您的过滤器功能将是这样的:

    $scope.filterEmployees = function(employee) {
        if (employee.saving) return true;
        // rest of the filtering...
    }
    

    【讨论】:

    • 感谢您的回复。我实际的ngRepeat 过滤器比我的示例更复杂,我不想重新发明轮子。有什么方法可以做到这一点,而不需要我重新滚动 angular 附带的所有过滤器行为?
    • 您可以随时通过$filter在过滤器功能中使用其他过滤器。
    • 是的,刚刚Dylan说了什么!你不必重新发明任何东西。我真的想不出任何其他方法。
    猜你喜欢
    • 1970-01-01
    • 2013-12-13
    • 2013-06-11
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    相关资源
    最近更新 更多