【问题标题】:How to implement filter in strict mode in ng-grid?如何在 ng-grid 中以严格模式实现过滤器?
【发布时间】:2023-03-04 17:59:02
【问题描述】:

我正在使用 ng-grid 填充数据。我正在使用 ng-grid 内部过滤器。但这不是我想要的。

数据是

$scope.myData = [{name: "Moroni", age: 50},
                   {name: "Tiancum", age: 43},
                   {name: "Jacob", age: 27},
                   {name: "Nephi", age: 29},
                   {name: "Enos", age: 34}];

如果我搜索 “Moroni”,我会得到我需要的输出。但是如果我搜索 "roni" ( Moroni ) 我不应该看到 Moroni 的名字。我的问题是如何应用键值的严格比较。

我希望过滤器只有在

时才为真

filterText == 'Moroni' [完全匹配文本而不是子字符串]

【问题讨论】:

    标签: javascript angularjs filter ng-grid


    【解决方案1】:

    在过滤器的角度文档中:http://docs.angularjs.org/api/ng.filter:filter

    您可以在comparator 下找到这个:

    true: A shorthand for function(actual, expected) { return angular.equals(expected, actual)}. 
    this is essentially strict comparison of expected and actual.
    

    所以试试filter:filterText:true

    【讨论】:

    • 感谢您的回答。它在 Angular 过滤器中完美运行。我将如何在 ng-grid 过滤 中实现这一点
    • 很抱歉。根据 ng-grid 文档,似乎没有对角度过滤的类似支持。你可能想看看useExternalFilter
    猜你喜欢
    • 2013-12-24
    • 1970-01-01
    • 2012-07-31
    • 2023-04-07
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多