具有角滤波器或condtion
问题描述:
对于使用角度滤波器滤波JavaScript数组的语法是具有角滤波器或condtion
$滤波器(“过滤器”)(阵列,表达,比较器,anyPropertyKey)
作为每角文档第二参数表达可以采取
甲图案对象来过滤由阵列包含的对象 特定属性。例如{名称:“M”,电话:“1”}谓词将 返回具有含“M”,并在提及例如包含“1”
属性电话属性名项的阵列,我们越来越情况如姓名匹配“M” 和手机匹配的“1”
,但如何实现条件为名称匹配“M” 或手机匹配“1”
代码示例
var employees=[
{lastname:"john",firstname:"jack",age:40,sex:"m"},
{lastname:"Abby",firstname:"john",age:20,sex:"f"},
];
var filteredData =$filter('filter')(employees,{firstname:'john', lastname:'john'});
这导致了因为没有记录和应用 可我们试图筛选具有姓氏或名字为“约翰”
这是可能实现与使用了自定义过滤器
答
记录
var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', ['$scope', '$filter', function($scope, $filter){
var employees=[
{lastname:"john",firstname:"jack",age:40,sex:"m"},
{lastname:"Abby",firstname:"john",age:20,sex:"f"},
{lastname:"Abby",firstname:"mark",age:20,sex:"f"},
];
$scope.filteredData = $filter('filter')(employees, function(value){
return value.firstname == 'john' || value.lastname == 'john';
});
console.log($scope.filteredData);
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html ng-app="myApp">
<body>
<div ng-controller="myCtrl">
{{filteredData}}
</div>
</body>
</html>
你可以像下面一样使用。
$scope.filteredData = $filter('filter')(employees, function(value){
return value.firstname == 'john' || value.lastname == 'john';
});
显示您的代码和数据 – jitender
的可能的复制[AngularJs与 “或” 条件过滤?(https://*.com/questions/39554350/angularjs-filter-with-or-condition) –
@ jitender更新了问题 – lrvkiran