in angularJs有沒有辦法通過匹配兩個或多個字段來過濾ng-repeat? 例如,我想列出所有名字或姓氏中帶有字母「J」的人。 如果我使用當前函數它列出誰擁有被搜索匹配字符在這兩個名字字母「J」和姓ng-repeat過濾器或者等於名字或姓氏
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title>Welcome To My Homepage</title>
<link href="css/style.css" rel="stylesheet" />
<link href="css/bootstrap.min.css" rel="stylesheet" />
</head>
<body ng-controller="MyCtrl">
<div ng-controller="MyCtrl">
<input type="text" ng-model="search">{{search}}
<table border="1">
<tr ng-repeat="row in list | filter:{firstName:search} | filter:{lastName:search}">
<td>{{row.firstName}} {{row.lastName}}</td>
</tr>
</table>
</div>
<script src="js/jquery-2.2.1.js"></script>
<script src="js/angular.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', ['$scope','$http','$filter', function($scope,$http,$filter) {
$scope.list = [{
"id": 1,
"address": "New York City",
"firstName": "Jennifer",
"middleName": null,
"lastName": "Aniston"
}, {
"id": 1,
"address": "New York City",
"firstName": "Jennifer",
"middleName": null,
"lastName": "Leela"
}, {
"id": 2,
"address": "Beverley Hills",
"firstName": "Angelina",
"middleName": null,
"lastName": "Jolie"
}, {
"id": 3,
"address": "London",
"firstName": "Emma",
"middleName": null,
"lastName": "Watson"
}];
}]);
</script>
</html>
您需要創建過濾器定製的[自定義過濾器(https://stackoverflow.com/questions/15868248/how-to-filter-multiple-values-or-operation-in-angularjs) – Naimad
是,自定義過濾器是這種情況下的最佳解決方案! –