-1

I am trying to use the treepanel but I have received some data from an external api in the following format (see below), basically it's a json array that will automatically return a array with companies (B & A and T & C below) and each company would have a number of employees as children.

I am unsure how to get this working in the treepanel. I need the company to be displayed as a row that can be expanded to show the children.

Does a standard store support this, is my data in the correct format. I am a little lost on this.

"B & A": [
  {
    "name": "Fred",
    "code": "aan9"
  },
  {
    "name": "Walter",
    "code": "wxxs"
  }
],
"T & C": [
    {
    "name": "mary",
    "code": "assan9"
  },
  {
    "name": "Bart",
    "code": "sswxxs"
  }
]
halfer
  • 19,824
  • 17
  • 99
  • 186
Martin
  • 23,844
  • 55
  • 201
  • 327

1 Answers1

0

To implement a TreePanel, you need to create a TreeStore. Inside a TreeStore you need to follow a special way to manage your data. Your "child" items have to be under an array "children".

See the following correct JSON data for a TreeStore :

[{
    text: "B & A",
    leaf: false,
    children : [{
         text: "Fred",
         code: "aan9",
         leaf: true
    }, {
         text: "Walter",
         code: "wxxs",
         leaf: true
    }
]},{ 
    text: "T & C",
    leaf: false,
    children : [{
        text: "mary",
        code: "s",
        leaf: true
    }, {
        text: "Bart",
        code: "sswxxs",
        leaf: true
    }] 
}];

Here is a working Fiddle : http://jsfiddle.net/Xpe9V/1615/

Benoit Cuvelier
  • 806
  • 7
  • 23