0

I have an Array of customers.Each customer has an array of Field objects.I would like to filter the Array of customers so I get all the customers that have some specific Field.The customer array looks like that.

[{"id":236,
 "username":"Tsakos Ntinidis",
 "email":"[email protected]",
 "fields":[{"id":2,"name":"Entrepreneurship"},
                {"id":16,"name":"Sciences (Math, Physics, Chemistry etc)"}, 
                {"id":3,"name":"Engineering"},
                {"id":18,"name":"Journalism"}],
                "hasVideo":false,
                "profileDescription":null,"isNew":false},
 {"id":237,
 "username":"Nick Brown",
 "email":"[email protected]",
 "fields":[{"id":1,"name":"IT"},
                {"id":16,"name":"Sciences (Math, Physics, Chemistry etc)"}, 
                {"id":18,"name":"Journalism"}],
                "hasVideo":false,
                "profileDescription":null}]

and the list that populates the field select field is:

[{"id":1,"name":"Finance"},{"id":2,"name":"Entrepreneurship"},{"id":3,"name":"Engineering"},{"id":4,"name":"Economics"}]

And the html for the customer table is this:

 <select  ng-model="search.fields.field.id" ng-options="field.id as field.name for field in fields">
</select>

 <tr ng-repeat="customer in customers | orderBy:predicate:reverse | filter:search" ng-     controller="Controller">
                    <td class="id">{{customer.id}}</a></td>
                    <td>{{customer.userName}}</a></td>
 </tr>

My main problem is the array is empty after I filter so apparently something goes wrong. Thank you for your help

1 Answer 1

1

please see here http://jsbin.com/cozasamusinu/1/edit change select to

<select  ng-model="search.fields.id" ng-options="field.id as field.name for field in fields">
</select>

and in your reapeater

<tr ng-repeat="customer in customers |filter :{fields:search.fields.id}:true">

just now in your fileds array you've { id:1 name:Finance} and in {user id:1 name:IT}

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for not mentioning but i filter the list with other parameters as well <input type="text" class="filters" ng-model="search.userName" placeholder="Filter by Surename"/>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.