PDA

View Full Version : TreeStore and json dont work together



Forn
5 Aug 2012, 9:12 AM
Heelo. I have the TreePanel:



Ext.define('LeftPanel', {
extend: 'Ext.tree.Panel',
alias: 'widget.leftpanel',

id: 'treeMainMenu',
region: 'west',
collapsible: true,
collapsed: true,
title: 'Navigation',
split: true,
width: '30%',
minWidth: 200,
minHeight: 140,
useArrows: true,
viewConfig: {
singleSelect: true,
trackOver: true,
rootVisible: false,
emptyText: 'No data',
loadingText: 'Loading tree...'
}
});


DataSource:


/**
* Data source for Static Category.
*/
Ext.define('DSStaticCategory', {
extend: 'Ext.data.TreeStore',
model: 'ModelStaticCategory',

autoLoad: false,
proxy: {
type: 'ajax',
url: baseJavaUrl,
reader: {
type: 'json',
root: 'data'
}
},
root: {
text: 'Root',
id: '0',
expanded: true
}
});


And the code:


var treeStore = new Ulmart.WebAdmin.store.DSStaticCategory();

var action = new JavaAction();
action.setActionCode("StaticCategoryTree");
var json = Ext.JSON.encode(action);

Ext.getCmp("treeMainMenu").store = treeStore;

Ext.getCmp('treeMainMenu').store.load({
params: {
ulmartAction: json
}
});


The result for the store is as JSON:



{"errorMessage":null,"success":true,"loggedIn":true,"username":"forn","data":[{"text":"Why you?","id":1,"cls":"","leaf":true}],"total":1}


So why in the tree the node with text "Why you?" not displayed?

tobiu
5 Aug 2012, 11:37 AM
my first guess would be:


rootVisible: false,

vietits
5 Aug 2012, 5:54 PM
The store is required at the time of creating TreePanel. Assigning store to the existing TreePanel as you do won't work.


Ext.getCmp("treeMainMenu").store = treeStore; <- this won't work