Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:按内部数组对象字段过滤_Javascript_Angularjs - Fatal编程技术网

Javascript AngularJS:按内部数组对象字段过滤

Javascript AngularJS:按内部数组对象字段过滤,javascript,angularjs,Javascript,Angularjs,我有以下数据: organizations:[{ name: "foo", contacts: [{ firstName = "John", lastName = "Doe", email = "john.doe@email.com"

我有以下数据:

organizations:[{
                name: "foo",
                contacts: [{
                             firstName = "John",
                             lastName = "Doe",
                             email = "john.doe@email.com"
                          },...]
               },...]
然后我有一个表,其中列出了所有组织,我想知道是否可以根据名字过滤器或电子邮件过滤器过滤表中的行

例如,我有以下代码:

<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>

{{organization.name}
{{client.contacts[0].firstName}{{{client.contacts[0].lastName}
{{客户端。联系人[0]。电子邮件}
它只能通过“名称”字段进行过滤。我试过这样的方法:

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


但它会在contacts数组中的所有对象字段中进行搜索,但我想特别按firstName进行搜索。我该怎么做?

使用类似于
filter:filterBy
的过滤功能

示例(依赖于下划线.js):


你试过了吗?我试过了,但不起作用,我想是因为联系人是一个数组。关于筛选器,需要注意的一点是,它们需要快速。如果出于任何原因,您看到筛选器正在减慢速度,请尝试$watch刷新筛选器属性,然后手动筛选您的数组,并在模板ng中对已筛选的ArrayInDect@LiviuT重复此操作。对于少量的行,过滤器应该很好。
scope.filterBy = function(row) {
    return !!_.where(row.contacts, {firstName:scope.search.name}).length;
}