tags:

views:

2751

answers:

3

I've got a basic ExtJS question, which I can't seem to resolve based on reading the docs and searching. Currently I have a TreePanel that loads JSON directly from a URL. I'm trying to separate the data from the view, so that I can also use that data to feed into an OpenLayers map (using GeoExt). How can I point a TreePanel to an Ext.data.Store rather than to a URL?

+7  A: 

TreePanels use TreeLoaders, not Stores, to load data. The reason is that trees require hierarchical data, while Stores are flat table structures and do not support hierarchies. The basic data objects are also different (Record vs. Node). Of course you could store your own hierarchical data in a Store using parent/child keys, but there is not anything like this built in for Ext components at this time. If you are trying to cache tree data, you might have to roll your own solution for that.

bmoeskau
A: 

In your TreePanel config, just point to your data url.

  loader: new Ext.tree.TreeLoader({
    url: '/path/to/data.json',
    requestMethod: 'GET',
    preloadChildren: true
  })

If you need a Store for this data, it could get tricky as noted by bmoeskau, since the data format could differ.

Jonathan Julian
A: 

in our app we're using a combination of a tree panel and a dataview, both are making requests for data (tree using traditional tree loader) and data view using store. both are submitting to the same url, and yes, there are two calls, but results are returned properly formatted by a view parameter ( tree or dataview ) and the results are the same, just decorated differently.

it would be ideal to have one call, central data, but this seems to work acceptably.

write a few functions to abstract the parsing of (record to node) and you end up with a general way of accessing data for either.

ruzz
This is definitely a pain point for a lot of people. The Ext 4.0 road map includes "relational" stores, so let's hope that solves this issue finally. http://www.extjs.com/products/js/roadmap.php
bmoeskau