PDA

View Full Version : Why not customize TreeStore Proxy Reader



firstblood
25 Apr 2013, 1:27 AM
myCode


Ext.define("MyTreeStore", {
extend: "Ext.data.TreeStore",
proxy: {
type: 'ajax',
url: 'TreeApiController.do?method=queryTreeList',
reader: {
type: 'json'
}
},
root: {
id: -1,
expanded: true,
text: "My Root"
},
autoLoad: true
});

var store = Ext.create("MyTreeStore");

Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 250,
height: 500,
store: store,
rootVisible: true,
renderTo: Ext.getBody()
});

the server result
[{"text":"java","leaf":false,"children":[{"text":"hibernate","leaf":true},{"text":"spring","leaf":true}]]

There is no problem with the above

But the wording of the following error will occur way??


Ext.define("MyTreeStore", {
extend: "Ext.data.TreeStore",
proxy: {
type: 'ajax',
url: 'TreeApiController.do?method=queryTreeList',
reader: {
type: 'json',
root: 'data'
}
},
root: {
id: -1,
expanded: true,
text: "My Root"
},
autoLoad: true
});


root = data
and the server result is
{"success":true,"data":[{"text":"java","leaf":false,"children":[{"text":"hibernate","leaf":true},{"text":"spring","leaf":true}]]}

Why can not specify root = data ???

slemmon
26 Apr 2013, 2:51 PM
You should be able to. It worked ok using the code / data below on ExtJS 4.2:



var treeStore = Ext.create('Ext.data.TreeStore', {
root: {
expanded: false
}
, proxy: {
type: 'ajax'
, url: 'data/json.json'
, reader: {
type: 'json'
, root: 'data'
}
}
});




var tree = Ext.create('Ext.tree.Panel', {
store: treeStore,
width: 300,
height: 200,
renderTo: Ext.getBody()
});




{
"success": true,
"data": [
{"text": "AAA", "leaf": false},
{"text": "BBB", "leaf": false},
{"text": "CCC", "leaf": false}
]
}

firstblood
27 Apr 2013, 5:00 PM
Can always find the answers I need here Thank you very much