javascriptangularjsangular-filters

Nested object filtering - Angular


Right now I have an array of complex objects that have objects inside of objects. I'm trying to use an input field to filter down the list (in an ng-repeat), but for some reason I'm only getting results from the top level.

[
  {
    "id": 1,
    "guid": "a97f722e-cef4-a125-351b-77c281c88556",
    "groups": [
      {
        "name": "Another Test",
        "id": 1
      },
      {
        "name": "Angular",
        "id": 9
      }
    ],
    "addresses": [
      {
        street: "123 Test Ave",
        city: "New York",
        state: "New York"
      }
    ]
  },
  {
    "id": 2,
    "guid": "a97fbbbb-cccc-a125-351b-77c281c88556",
    "groups": [
      {
        "name": "Garbage",
        "id": 2,
        "stuff": [
          {
            "name": "Dennis",
            "anothernest": [
              {
                "test": "Bob"
              },
              {
                "test": "Bob2"
              }
            ]
          }
        ]
      },
      {
        "name": "Test",
        "id": 7
      }
    ],
    "addresses": [
      {
        "street": "345 Test Ave",
        "city": "Los Angeles",
        "state": "California"
      }
    ]
  }
]

This is a similar structure (albeit simplified). For some reason though I have no problem filtering any of these nested objects based on a search: http://jsfiddle.net/7aeL2yd2/

What would prevent me from doing this on a bigger data structure?

Edit Looks like it's an Angular 1.3 issue. It worked on 1.2, but when I upgrade it to 1.3 (like my app is) it no longer works. http://jsfiddle.net/7aeL2yd2/2/


Solution

  • This issue was raised seven days ago on GitHub:

    fix(filterFilter): filter deep object by string

    And it looks like a fix for it was checked in 12 hours ago:

    fix(filterFilter): make $ match properties on deeper levels as well

    I don't really know how AngularJS's build workflow works or how they release brand new versions, but at any rate, it looks like a solution for your issue is on the way. In the meantime, perhaps you can get by with version 1.2?