PDA

View Full Version : Error on populating Ext Js Tree with JSON store



seema
7 Dec 2011, 4:25 PM
I'm trying to create ExtJs Tree using this code.


Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', mapping: 'name'}
]
});

var store = Ext.create('Ext.data.TreeStore', {
model: 'User',
proxy: {
type: 'ajax', // rest
url : 'tree.json',
reader: {
type: 'json',
root: 'pdb.user.filterResults.partnerFilter.column'
}
},
autoLoad: true,
autoSync: true,
root: {
name: "Root node",
id: '0',
expanded: true
}
});

My JSON structure is-

{"pdb":{"user":{"filterResults":{"partnerFilter":{"column":[{"id":"HomeGeography","name":"Home GEO"},{"id":"BusinessModel","name":"Business Model"}]}}}}}

I'm getting problem in populating tree.

Please suggest

skirtle
7 Dec 2011, 10:16 PM
I'm getting problem in populating tree.

Could you be more specific?

A few suggestions.

Get rid of autoLoad and autoSync.

Your model is missing your id field. Is that intentional?

A treepanel defaults to having a single column with a dataIndex of text. Have you configured your name field as a column in your tree?


columns: [{
dataIndex: 'name',
xtype: 'treecolumn'
}]

seema
8 Dec 2011, 9:47 AM
Hi Skirtle,
I worked on your suggestion, but the problem still there. error is in this part of code.


var store = Ext.create("Ext.data.TreeStore", {
model: "Pdb",
proxy: {
type: "ajax", // rest
url : "tree.json",
reader: {
type: "json",
root: "pdb.user.filterResults.partnerFilter.column"
}
},
root: {
name: "Root node",
id: "0",
expanded: true
},
sorters: [{
property: "id",
direction: "ASC" // DESC
}]
});

Error is "obj.pdb is undefined". is it because of nested root in store. we used to work in the same manner in data.store. Is this feature not supported in data.TreeStore? If I remove nested root and modify my json as well, then its working fine. Please suggest.

skirtle
9 Dec 2011, 12:23 AM
If you can remove the need for a root then do. Trees are currently a bit confused and use the root to signify the node containing the children. I imagine the problem is trying to read nested children, even though you don't have any.

If you can't simplify your JSON then I think you may have to resort to overriding getResponseData on the reader.