-
20 Sep 2012 5:50 PM #1
Answered: How to restructure data returned by server to treestore data?
Answered: How to restructure data returned by server to treestore data?
My server returns array data like below
But Ext.data.TreeStore expects it to beCode:[ {id: '1', parent: '', name: 'AB'}, {id: '2', parent: '1', name: 'A'}, {id: '3', parent: '1', name: 'B'}, {id: '4', parent: '', name: 'CD'}, {id: '5', parent: '4', name: 'C'}, {id: '6', parent: '4', name: 'D'}, {id: '7', parent: '', name: 'E'} ]
I can write an algorithm to transform it but I do not know where to place it. I tried inside the load listener but the records passed to the function is not raw (it is array of Model). And suppose I know how to iterate and transform it, I do not know have idea on how I will set the records with the newly structured data.Code:{'root': 'theroot', 'children': [ {id: '1', name: 'AB', children: [ {id: '2', name: 'A'}, {id: '3', name: 'B'} ] }, {id: '4', name: 'CD', children: [ {id: '5', name: 'C'}, {id: '6', name: 'D'} ] }, {id: '7', name: 'E'} ] }
Anyone there who had this same requirement before and managed to come up with a solution? Thank you
-
Best Answer Posted by crysfel
The easiest way to do it is to just make a regular ajax request, create the correct object structure and then load the store.
RegardsCode:Ext.Ajax.request({ url : 'data.json', success : processresponse }); function processresponse(response,options){ var data = Ext.decode(response.responseText); //create the new structure var tree = createTree(data); store.setRootNode(tree); }
-
20 Sep 2012 9:14 PM #2
The easiest way to do it is to just make a regular ajax request, create the correct object structure and then load the store.
RegardsCode:Ext.Ajax.request({ url : 'data.json', success : processresponse }); function processresponse(response,options){ var data = Ext.decode(response.responseText); //create the new structure var tree = createTree(data); store.setRootNode(tree); }
-
20 Sep 2012 9:39 PM #3


Reply With Quote