尝试这个fiddle http://jsfiddle.net/qa98r/2/.
本质上,我创建了一个子结构,用于在显示的数据结构中进行过滤,并仅在该属性上进行过滤(例如“filterTerms”):
HTML:
<div ng-controller="MyCtrl">
<input type="text" ng-model="search.filterTerms">
<table border="1">
<tr ng-repeat="row in list | filter:search">
<td>{{row.firstName}} {{row.lastName}}</td>
</tr>
</table>
</div>
JavaScript:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.list = [{
"id": 1,
"address": "New York City",
"firstName": "Jennifer",
"middleName": null,
"lastName": "Aniston",
"filterTerms": {
"firstName": "Jennifer",
"middleName": null,
"lastName": "Aniston",
}
}, {
"id": 1,
"address": "New York City",
"firstName": "Jennifer",
"middleName": null,
"lastName": "Leela",
"filterTerms": {
"firstName": "Jennifer",
"middleName": null,
"lastName": "Leela",
}
}, {
"id": 2,
"address": "Beverley Hills",
"firstName": "Angelina",
"middleName": null,
"lastName": "Jolie",
"filterTerms": {
"firstName": "Angelina",
"middleName": null,
"lastName": "Jolie",
}
}, {
"id": 3,
"address": "London",
"firstName": "Emma",
"middleName": null,
"lastName": "Watson",
"filterTerms": {
"firstName": "Emma",
"middleName": null,
"lastName": "Watson",
}
}];
}
对于这种情况,您可以通过将所有名称放入一个字段来进一步简化这一点(请参阅 fiddlehere http://jsfiddle.net/VsdR3/1/:
HTML:
<div ng-controller="MyCtrl">
<input type="text" ng-model="search.filterTerm" />
<table border="1">
<tr ng-repeat="row in list | filter:search">
<td>{{row.first}} {{row.last}} {{row.address}}</td>
</tr>
</table>
</div>
JavaScript:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.list = [{
"id": 0, "first": "Jenny", "last": "Sorenson", "address": "123 W. Wallnut St.",
"filterTerm": "Jenny Sorenson"
},{
"id": 0, "first": "Susan", "last": "Hinkle", "address": "456 W. Doorbell Dr.",
"filterTerm": "Susan Hinkle"
},{
"id": 0, "first": "Rachel", "last": "Karlyle", "address": "789 W. Sunset Blvd.",
"filterTerm": "Rachel Karlyle"
},{
"id": 0, "first": "Gwen", "last": "Lippi", "address": "0 W. Silly Cir.",
"filterTerm": "Gwen Lippi"
}]
}