我有以下数据:
organizations:[{
name: "foo",
contacts: [{
firstName = "John",
lastName = "Doe",
email = "john.doe@email.com"
},...]
},...]然后我有一个表,其中列出了所有组织,我想知道是否可以根据firstName筛选器或电子邮件筛选器筛选表中的行。
例如,我有这样的代码:
<input type="text" id="name" ng-model="search.name">
<tr ng-repeat="organization in organizations | filter:search">
<td>{{organization.name}}</td>
<td>{{client.contacts[0].firstName}} {{ client.contacts[0].lastName }}</td>
<td>{{client.contacts[0].email}}</td>
</tr>它只对“name”字段进行过滤。我尝试了这样的东西:
<input type="text" id="firstName" ng-model="search.contacts">但是它在contacts数组中对象的所有字段中进行搜索,但我想具体按firstName进行搜索。我该怎么做呢?
发布于 2013-07-19 20:51:47
使用像filter:filterBy这样的过滤函数。
示例(依赖于underscore.js):
scope.filterBy = function(row) {
return !!_.where(row.contacts, {firstName:scope.search.name}).length;
}https://stackoverflow.com/questions/17744737
复制相似问题