1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    23
    Vote Rating
    0
    demotics2002 is on a distinguished road

      0  

    Default 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
    Code:
    [
       {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
    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'}
       ]
    }
    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

  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.

    Code:
    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);
    }
    Regards

  3. #2
    crysfel's Avatar
    Join Date
    Feb 2008
    Location
    New York, USA
    Posts
    215
    Answers
    7
    Vote Rating
    8
    crysfel will become famous soon enough

      1  

    Default


    The easiest way to do it is to just make a regular ajax request, create the correct object structure and then load the store.

    Code:
    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);
    }
    Regards

  4. #3
    Sencha User
    Join Date
    Dec 2010
    Posts
    23
    Vote Rating
    0
    demotics2002 is on a distinguished road

      0  

    Default


    OMG!!! You saved my day! Thank you...

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi