demotics2002
20 Sep 2012, 5:50 PM
My server returns array data like below
[
{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'}
]
But Ext.data.TreeStore expects it to be
{'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'}
]
}
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.
Anyone there who had this same requirement before and managed to come up with a solution? Thank you
[
{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'}
]
But Ext.data.TreeStore expects it to be
{'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'}
]
}
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.
Anyone there who had this same requirement before and managed to come up with a solution? Thank you