angularjs中的严格模式过滤器不起作用

时间:2016-06-15 17:43:17

标签: angularjs

enter image description here

以下代码行不起作用。它给出了所有列表。但为什么它没有给出理想的结果?

$scope.search = "Ernst Handel";
$scope.disableFilter = false;
$scope.records = [{
        "Name": "Alfreds Futterkiste",
        "Country": "Germany"
    }, {
        "Name": "Berglunds snabbköp",
        "Country": "Sweden"
    }, {
        "Name": "Centro comercial Moctezuma",
        "Country": "Mexico"
    }, {
        "Name": "Ernst Handel",
        "Country": "Austria"
    }, {
        "Name": "Ernst Handelll",
        "Country": "Austriaaa"
    }]

<tr ng-repeat="x in records | filter:(!disableFilter || '') && {Name:search}.true ">
    <td>{{x.Name}}</td>
    <td>{{x.Country}}</td>
</tr>`

以表格格式提供所有项目,如下所示。

Alfreds Futterkiste Germany
Berglunds snabbköp  Sweden
Centro comercial Moctezuma  Mexico

但我想要的结果应该只是

Ernst Handel    Austria

再次感谢。但我想在某些条件下使用过滤器以及严格匹配

<tr ng-repeat="x in records | filter:(!disableFilter || '') && {Name:search}.true ">

根据disableFilter,应该应用我的过滤器。

1 个答案:

答案 0 :(得分:0)

以下是您需要的工作过滤器:PLUNK

<table class ="table">
  <tr style="font-weight:bold; background-color:grey;">
    <td>Name</td>
    <td>Country</td>
  </tr>
  <tr ng-repeat="x in records | filter:search">
        <td>{{x.name}}</td>
        <td>{{x.country}}</td>
  </tr>`
</table>

$scope.search = "Alfreds Futterkiste";

$scope.records = [
   {
       name: "Alfreds Futterkiste",
       country: "Germany"
   }, {
       name: "Berglunds snabbköp",
       country: "Sweden"
   }
]

如果您担心大小写,请告诉我们。