0

I have an application that I am constructing with a friend and we have a very big problem: I have a very big json with some nested arrays an objects, I am using a filter with an ng-model="search" the filter (search) works great with the top level array which is named sports, but once I try to search through the leagues array, the filter returns nothing. I saw in another question that I can search(filter) based on nested properties which is exactly what I want. I tried to follow the example answer on that question but I am having a problem trying to solve this. Someone else says: that is not possible with this kind of matching that you are trying because you want to filter through a matching sport.name and all of his matching and not non matching leagues or a non matching sport.name and only his matching leagues.

json

     [
      {
        "name": "Cricket",
        "leagues": []
      },
      {
        "name": "NBA Games",
        "leagues": [
          {
            "name": "NBA",
            "sport": {
              "id": 8,
              "name": "NBA Earliest"
            },
            "lineType": "G",
            "priority": [
              1,
              3
            ],
            "part": "0"
          }
        ]
      },
      {
        "name": "COLLEGE Basketball",
        "leagues": [
          {
            "name": "College - NCAA BASKETBALL",
            "sport": {
              "id": 24,
              "name": "College Basketball"
            },
            "lineType": "G",
            "priority": [
              0,
              4
            ],
            "part": "0"
          },
          {
            "name": "NCAA BASKETBALL ADDED GAMES",
            "sport": {
              "id": 24,
              "name": "College Basketball"
            },
            "lineType": "G",
            "priority": [
              1,
              4
            ],
            "part": "0"
          },
          ...

my html

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

<div ng-repeat="sport in sports | filter: query">

     <!-- searching (filtering) great --> 
     <div>{{sport.name}}</div>
   </div>

   <div ng-repeat="league in sport.leagues | filter: query">

      <!-- here is not filtering at all -->
        {{league.name}}
   </div>
</div>

can I do it this way I am trying or how do I implement a custom filter for this ?

7
  • my bower.json says: angular 1.3.8 Commented Feb 6, 2015 at 17:54
  • I assume your second ng-repeat is supposed to be nested inside the first? In your example above it's not. Commented Feb 6, 2015 at 17:55
  • is because you can not see sports, but sports is the parent/top array, and then the rest comes up. And yes, the second ng-repeat is the one nested Commented Feb 6, 2015 at 17:59
  • If the query matches a league, do you want both the sport and the league to show or only the league? Commented Feb 6, 2015 at 18:01
  • both, I mean, the query has to match sports and leagues also. if the query does not find any of those on the list, then a message comes up "did not match any search criteria" Commented Feb 6, 2015 at 18:02

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.