0

I have an array with the name of sports, json:

 [
  {
    "id": 26,
    "name": "LIVE Betting",
    "priority": 0,
    "leagues": []
  },
  {
    "id": 8,
    "name": "NBA",
    "priority": 3,
    "leagues": [
      {
        "id": 5932,
        "parent": 1000,
        "name": "NBA",
        "sport": {
          "id": 8,
          "name": "NBA"
        },
        "lineType": "G",
        "priority": [
          1,
          3
        ],
        "part": "0"
      }
    ]
  },
  {
    "id": 24,
    "name": "College Basketball",
    "priority": 4,
    "leagues": [
      {
        "id": 2599,
        "parent": 1000,
        "name": "NCAA BASKETBALL",
        "sport": {
          "id": 24,
          "name": "College Basketball"
        },
        "lineType": "G",
        "priority": [
          0,
          4
        ],
        "part": "0"
      },
      {
        "id": 2631,
        "parent": 1000,
        "name": "NCAA BASKETBALL ADDED GAMES",
        "sport": {
          "id": 24,
          "name": "College Basketball"
        },
        "lineType": "G",
        "priority": [
          1,
          4
        ],
        "part": "0"
      },
      ...

within that array you can see another with the name of "leagues": [{...}] which contains an object, my filter is searching fine thru the top array which is sports but once I try to find thru the "name" within leagues array then my app shows up a message that the filter is empty.

<input type="search" ng-model="query">

<div ng-repeat="sport in sportsFilter = (sports | filter:query)">
        <!--this array works fine-->
        <strong>{{sport.name}}</strong>
      </div>
      <div ng-repeat="league in sport.leagues">
        <!--this one not works at all-->
        {{league.name}}
      </div>
</div>

I've been trying all the ways already, with a resolve, with different models, etc and actually I just realized that I need a custom filter so I would like you to give me a hand because I do not where to start from with it.

or is there any easier way ?

7
  • You want to use the same query to search objects in leagues array? Do you want to match any property of leagues? Commented Feb 5, 2015 at 18:12
  • yes, the same query and the property name. Commented Feb 5, 2015 at 18:16
  • See if this helps: stackoverflow.com/a/28160037/968155 Commented Feb 5, 2015 at 18:22
  • i didn't get that with my code: I have it this way on mine ng-repeat="league in sport.leagues | filter: {leagues: {name: query}} and still not working,also remember that I have 2 ng-repeat working with the same ng-model='query' Commented Feb 5, 2015 at 19:02
  • actually I have it working this way ng-repeat="sport in sportsFilter = ( sports | filter: {leagues: [{name:query}]} )" but now my issue is with the sports array, I need to do something like: ng-repeat="sport in sportsFilter = ( sports | filter: {leagues: [{name:query}]} | filter:query)" but still not working Commented Feb 6, 2015 at 15:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.