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

しかし、contacts 配列内のオブジェクトのすべてのフィールドを検索しますが、具体的には firstName で検索したいと考えています。どのようにできるのか?

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 に答える