1

我有以下数据:

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>

它仅按“名称”字段过滤。我试过这样的事情:

<input type="text" id="firstName" ng-model="search.contacts">

但它搜索联系人数组中对象的所有字段,但我想专门按名字搜索。我能怎么做?

4

1 回答 1

-1

使用过滤器功能,如filter:filterBy.

示例(依赖 underscore.js):

scope.filterBy = function(row) {
    return !!_.where(row.contacts, {firstName:scope.search.name}).length;
}
于 2013-07-19T12:51:47.347 回答