0
votes

I have a tree datastructure with nested data.

TreeNodes and DataNodes. Like in a filesystem, the TreeNodes are the folders and the DataNodes are the files.

But the JSON structure is like this:

{
  name: 'root',
  data: [
    [a, b, 100, 23],
    [a, b, 100, 23],
    [a, b, 100, 23]
    ...
  ]
  children: [
    {
      name: 'child1',
      data: [...],
      children: [...]
    },
    {
      name: 'child2',
      data: [...],
      children: [...]
    },
    ...
  ]
}

I want to parse the children to TreeNodes and the data arrays to DataNodes, and use them in one TreeStore.

Is this possible?

ATM I got TreeNodes and every Tree node has an association for its data records, which is a suboptimal solution.

1

1 Answers

1
votes

I have a similar situation. What you need to do is create a model class that encompass both data types (extract overlapping properties). As far as the tree store it wont distinguish record types, but you can customize the look of the tree through icons to give each record type a distinct look. The data must be the same though, for example Name property must be the same for both record types.

Since your JSON structure from server response is somewhat odd you have to parse it yourself and shape into the structure the treestore expects. Alternatively, you'll need to get control of your server side implementation and tweak it there.