AngularJS 过滤器不会过滤等于 0 的值
AngularJS filter won't filter values that are equal to 0
我有以下搜索输入:
<input type="text" ng-model="search.Kkz">
我有以下 ng-repeat:
<tr class="ListItem" ng-class-odd="'Odd'" ng-class-even="'Even'"
ng-repeat="item in Prios | filter:search | filterMultiple:{Sprache:spracheSelectedItem} | orderBy:predicate:reverse | startFrom:currentPage*pageSize | limitTo:pageSize"
ng-click="setSelectedRow(item)" ng-class="{'Selected': item == selectedRow}">
目前 Kkz 字段可以有 2 个值(3000 和 0)。当我搜索数字 3000 时,它 returns 是一个正确的列表。但是当我搜索值“0”时,没有任何反应,就好像它没有在我正在搜索的 table 列中找到该值。
默认情况下,过滤器会查找不区分大小写的子字符串匹配项。它在这里找到 3000 内的 0,因此 3000 和 0 都匹配。
对于简单的字符串数组,您可以使用 filter:search:true
,在这种情况下,如果搜索是一个对象,创建您自己的比较器会有所帮助:
在HTML中添加比较函数的名称:
... | filter:search:compare | ...
在控制器中:
$scope.compare = function (actual, expected) {
// !expected: All records pass when no search value is specified.
// == instead of ===: Coerce the numbers from the array into strings to
// properly compare to the string from the input.
return (!expected || actual == expected);
};
当你说什么都没发生。你到底什么意思?您仍然得到相同的结果还是没有结果?
会不会是因为你用filter搜索0的时候也匹配到3000?
示例:
<!doctype html>
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.6/angular.min.js"></script>
</head>
<body ng-app="">
<div ng-init="values = [0,555,3000]"></div>
Search: <input ng-model="searchText">
<ul ng-repeat="value in values | filter:searchText">
<li>{{value}}</li>
</li>
</table>
</body>
</html>
有关此的工作示例,请参阅 http://plnkr.co/edit/CEt6XKP5ylQtXc2hhsx4?p=preview。
如果不是这种情况,请post更多代码。
我有以下搜索输入:
<input type="text" ng-model="search.Kkz">
我有以下 ng-repeat:
<tr class="ListItem" ng-class-odd="'Odd'" ng-class-even="'Even'"
ng-repeat="item in Prios | filter:search | filterMultiple:{Sprache:spracheSelectedItem} | orderBy:predicate:reverse | startFrom:currentPage*pageSize | limitTo:pageSize"
ng-click="setSelectedRow(item)" ng-class="{'Selected': item == selectedRow}">
目前 Kkz 字段可以有 2 个值(3000 和 0)。当我搜索数字 3000 时,它 returns 是一个正确的列表。但是当我搜索值“0”时,没有任何反应,就好像它没有在我正在搜索的 table 列中找到该值。
默认情况下,过滤器会查找不区分大小写的子字符串匹配项。它在这里找到 3000 内的 0,因此 3000 和 0 都匹配。
对于简单的字符串数组,您可以使用 filter:search:true
,在这种情况下,如果搜索是一个对象,创建您自己的比较器会有所帮助:
在HTML中添加比较函数的名称:
... | filter:search:compare | ...
在控制器中:
$scope.compare = function (actual, expected) {
// !expected: All records pass when no search value is specified.
// == instead of ===: Coerce the numbers from the array into strings to
// properly compare to the string from the input.
return (!expected || actual == expected);
};
当你说什么都没发生。你到底什么意思?您仍然得到相同的结果还是没有结果?
会不会是因为你用filter搜索0的时候也匹配到3000?
示例:
<!doctype html>
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-beta.6/angular.min.js"></script>
</head>
<body ng-app="">
<div ng-init="values = [0,555,3000]"></div>
Search: <input ng-model="searchText">
<ul ng-repeat="value in values | filter:searchText">
<li>{{value}}</li>
</li>
</table>
</body>
</html>
有关此的工作示例,请参阅 http://plnkr.co/edit/CEt6XKP5ylQtXc2hhsx4?p=preview。
如果不是这种情况,请post更多代码。