-
27 Feb 2013 12:42 PM #1
Answered: TreePanel from folder path or json response
Answered: TreePanel from folder path or json response
Hi,
Is possible to show a tree panel from a folder path, for example: c:/ show all folders, subfolders and files?
Thx
-
Best Answer Posted by wojteks27
You are missing root property in your JSON.
You need to make that JSON an array, like in my example :
Notice the top-level array. Try making your function return JSON with top-level array labeled "children" and get back to usCode:{ "children": [{ "id": "netbeans-7.2-ml-linux.sh", "text": "netbeans-7.2-ml-linux.sh", "leaf": true }, { "id": "Sam", "text": "Sam", "leaf": false, "children": [{ "id": "testDoc3.txt", "text": "testDoc3.txt", "leaf": true }] }, { "id": "Empty", "text": "Empty" }, { "id": "testDoc3.txt", "text": "testDoc3.txt", "leaf": true }, { "id": "soapUI-x32-4.5.1.sh", "text": "soapUI-x32-4.5.1.sh", "leaf": true }] }
PS.
@mkrakowski
As to the "totalProperty" it is only relevant when paging
Code:This is only needed if the whole dataset is not passed in one go, but is being paged from the remote server
-
27 Feb 2013 12:58 PM #2Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,103
- Vote Rating
- 97
- Answers
- 171
No, because you don't have access to the client file system from the browser.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
27 Feb 2013 1:04 PM #3
Ok, I have a method that I access through a controller that returns me the folder structure (json).
How I convert that response to a tree store like.
Thx
-
27 Feb 2013 1:06 PM #4
Really the main porpuse is to show me the directory that I consult through a SSH request on java and I return a json with the structure
-
28 Feb 2013 2:00 AM #5
JSON tree format
JSON tree format
You have to format the JSON response properly for the Ext.data.TreeStore reader to parse.
Use correct root name (you should use this name as store.proxy.reader.root property) in your JSON
Example :
Code:Ext.define('Departments.store.TreeStore', { extend:'Ext.data.TreeStore', id:'DepartmentsTreeStore', model:'Departments.model.Department', root:{ expanded:true, id:0, text:'Departments' }, proxy:{ type:'ajax', url:'dzialy/lista', reader:{ type:'json', root:'depts' } } });It is important that every node which is not a leaf, contain an array of leafs in a property named the same as root.Code:{ "depts":[ { "text": "Maths", "id": "mathDept", "depts": [ { "text":"X1", "id": "x1", "leaf": true }, { "text":"X2", "id": "x2", "leaf": true} ] }, { "text": "Biology", "id": "bioDept", "depts": [ { "text": "Y1", "id": "y1", "leaf": true}, { "text": "Y2", "id": "y2", "leaf": true} ] }, { "text": "English", id: "engDept", "depts": [ { "text": "Z1", "id": "z1", "leaf": true}, { "text": "Z2", "id": "z2", "leaf": true}, { "text": "Z3", "id": "z3", "leaf": true} ] } ] }
Try it out tell me if it worked for you.
Wojtek
-
4 Mar 2013 5:21 AM #6
Thanks wojteks27, I'm having problems returning the json, I'm working with java for the response and I return a json like yours but the tree is not showing up.
-
4 Mar 2013 5:24 AM #7
Check network pane in web inspector
Check network pane in web inspector
I'm assuming you use Chrome of Firefox.
In network pane in web inspector or Firebug there should be a trace of your request. Check whether the response is in correct format (doesn't get tweaked somewhere on the way). Check if the properties such as 'success' and 'root' have correct corresponding values in your JSON and in tree's reader.
Are there any error messages in console?
-
4 Mar 2013 5:28 AM #8
Code
Code
If you could post your source code it might help.
-
4 Mar 2013 3:43 PM #9
Thanks again wojteks27,
Ok, my store looks like this:
The answer that I'm receiving is a "json" but string like:Code:Ext.define('Test.store.FtpTree', { extend: 'Ext.data.TreeStore', autoLoad: false, proxy: { type: 'direct', directFn: Test.getFtpTree, reader:{ type:'json', root:'children' } }, root:{ expanded:true, id:0, text:'Folder' } });
Don't know what I'm missing here.Code:{id: 'netbeans-7.2-ml-linux.sh', text: 'netbeans-7.2-ml-linux.sh', leaf: true},{id: 'Sam', text: 'Sam', leaf: false, children: [{id: 'testDoc3.txt', text: 'testDoc3.txt', leaf: true}]},{id: 'Empty', text: 'Empty'},{id: 'testDoc3.txt', text: 'testDoc3.txt', leaf: true},{id: 'soapUI-x32-4.5.1.sh', text: 'soapUI-x32-4.5.1.sh', leaf: true}
-
4 Mar 2013 6:22 PM #10
This might be only relevant in a paging situation, but worth a shot. A total count param might be required in the returned json string, such as
PHP Code:totalProperty : 'totalCount',
Code:{"totalCount":"6","results":[{ //your json }]}


Reply With Quote