PDA

View Full Version : Load treestore with inline html json.



maps_tecnologia
6 Feb 2012, 6:45 AM
Hi, I am making a tree.Panel that in the future will have information suplied to it by a rest url.

Before implementing that, I am rendering a js html tag that contains my json.

The problem I am facing involves lodaing that data into my tree store.

I have a proxy defined that reads a 'dummy' url where I put a test json, but I cant find a way to define a proxy to read inline data.
Store


var store = Ext.create('Ext.data.TreeStore', { fields: [
{name: 'values', type: 'object'}
],
proxy: {
type: 'ajax',
url: './dummyOutput.js',
reader: {
type: 'json',
root: 'children'
}
}
});

Dummy json


{
"children": [
{
"values": {
"class": "a",
"name": "Joe"
},
"children": [
{
"values": {
"class": "a",
"name": "Bob"
},
"leaf": true,
"children": []
},
{
"values": {
"class": "a",
"name": "Fran"
},
"leaf": true,
"children": []
}
]
},
{
"values": {
"class": "b",
"name": "Lilian"
},
"leaf": true,
"children": []
}
]
}


Json I created programatically


{
"children": [
{
"children": [
{
"children": null,
"values": {
"abc": 123,
"def": 444
}
}
],
"values": {
"abc": 332,
"def": 666
}
}
]
}


I read the inline json and decode it as follows:


var data = Ext.decode(Ext.get('output.js').dom.innerHTML);

Doing
store.load(data); doesnt seem to work. The problem is figuring out a proxy for this situation.

Thanks for the time.

friend
6 Feb 2012, 7:39 AM
During testing, you can comment out your proxy and use the data attribute of the Store to house your JSON.

mitchellsimoens
6 Feb 2012, 8:02 AM
In the case of the TreeStore you need to add the children to the root node

maps_tecnologia
6 Feb 2012, 11:22 AM
root: {
children: data
}


That did it. =D

Thanks.