View Full Version : Load TreePanel after I have received and modified data from the server

16 Feb 2011, 6:41 PM
I have to make a couple of restful calls to the server to get the data that I need to load the TreePanel. I cannot find a good example of generating the data on my own after a call to the server.

First question is how can I tell that both calls to the server have returned. Currently I know that I can hook up a listener for each JsonStore (one for each call to the server). But I really need a way to have an event fired after both calls have returned. Not sure if this is possible.

function TreeDataModel() {
// Very simple store example
this.dataStore1 = new Ext.JsonStore({
url: '/data1',
root: 'data',
fields: ['id', 'folder']

this.dataStore2 = new Ext.JsonStore({
url: '/data2',
root: 'data',
fields: ['id', 'leafNode']

this.onStoreLoad= function () {
//this is where I would fill the data object with the information from the store
//problem is both stores need to have returned to fill out the information

// Also once I have all the info need to look up TreePanel and update its data
// I guess fire an event that my TreeModel is listening for, is it possible to fire an event
// that my tree model is listening for from this object?

// not sure if it is a good idea to set the same method for both stores
this.dataStore1.on('load', this.onStoreLoad, this);
this.dataStore2.on('load', this.onStoreLoad, this);


The other problem that I have is how to re-render my TreePanel once I have filled out the data object

In another javascript file I have my tree panel ui info

MyTreePanel = new Ext.tree.TreePanel({
useArrows: true,
autoScroll: true,
animate: true,
enableDD: true,
loader: new Ext.tree.TreeLoader(),
root: new TreeDataModel().data

So once there is data I need to re-render my TreePanel so it shows the information.

Has anyone done anything like this before?

Please help I am really lost on this one and wondering if I am even going in the right direction.

Thanks in advance!