1

I am using ng2-dropdown-treeview for a checkable treeview dropdown, this is the plunker for this package's demo.

Now, I am trying to load my dropdown options from a multilevel array of JSON objects like this:

this.leagueList=[
      {"category":[
        {
          "name":"Category 1",
          "id": "01",
          "leagues":[
            {
              "leagueName":"ABC",
              "leagueId":"01",
              "leagueClasses":[
                {
                  "className":"Class A",
                  "classId":"01"
                },
                {
                  "className":"Class B",
                  "classId":"02"
                },
                {
                  "className":"Class C",
                  "classId":"03"
                }
              ]
            },
            {
              "leagueName":"DEF",
              "leagueId":"02",
              "leagueClasses":[
                {
                  "className":"Class D",
                  "classId":"04"
                },
                {
                  "className":"Class E",
                  "classId":"05"
                },
                {
                  "className":"Class F",
                  "classId":"06"
                }
              ]
            }
          ]
        }
      ]}
    ];

Please view my code HERE I am getting error: Cannot read property 'length' of undefined

1
  • When you console log your leagueList, it give an object. But when you console leagueList.category is undefined. I'm not an expert in json array but I'll begin to find out how to access category sub object in the array. Commented Feb 2, 2017 at 16:49

1 Answer 1

1

Because leagueList is an array, not an object, you access to items of array by index first, then access to properties of each item. Example: leagueList[0].category.

I'm an author of ng2-dropdown-treeview. Post any question about it and I will help you.

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

Comments

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.