Threaded View

  1. #1
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    24
    Vote Rating
    0
    Answers
    2
    essex is on a distinguished road

      0  

    Default Answered: php json_encoded array and nestedlist

    Answered: php json_encoded array and nestedlist


    Hello,

    Is there anything special that needs to be done to special to make an array work in the nested list besides JSON encoding it in PHP. I have tried several times to prepare my array for the nested list but I get nothing.

    here is the code that produces my array

    Code:
     foreach ($channels as $index => $c)
                {
                    $node = $c['Content']['call_letters'];
                   // var_dump($node);
                  //  exit();
                
                     if ($node == $c['Content']['call_letters'])
                     {
                        //$refactor[$node][$index] = $c['Content'];
                       
                        $refactor[$node][$index] =
                        array('text' => $node,
                            'items'=> $c['Content']
                           );
                     }           
    
                }

    here is my array:

    Code:
    
    array   'KKYO' =>      array       0 =>          array           'text' => string 'KKYO' (length=4)           'items' =>              array               '_id' => string '4f128b336930f31137081969' (length=24)               'call_letters' => string 'KKYO' (length=4)               'channel_name' => string 'KKYO-Kyoto' (length=10)               'bcast_channel' => int 100               'start_time_utc' => float 1326650400               'program_id' => string '99344001' (length=8)               'title' => string 'Kyoto' (length=5)       1 =>          array           'text' => string 'KKYO' (length=4)           'items' =>              array               '_id' => string '4f128b336930f3113708196a' (length=24)               'call_letters' => string 'KKYO' (length=4)               'channel_name' => string 'KKYO-Kyoto' (length=10)               'bcast_channel' => int 100               'start_time_utc' => float 1326657600               'program_id' => string '99344001' (length=8)               'title' => string 'Kyoto' (length=5)       2 =>          array           'text' => string 'KKYO' (length=4)           'items' =>              array               '_id' => string '4f128b336930f3113708196b' (length=24)               'call_letters' => string 'KKYO' (length=4)               'channel_name' => string 'KKYO-Kyoto' (length=10)               'bcast_channel' => int 100               'start_time_utc' => float 1326664800               'program_id' => string '99344001' (length=8)               'title' => string 'Kyoto' (length=5)
    
    'KSEO' =>      array       15 =>          array           'text' => string 'KSEO' (length=4)           'items' =>              array               '_id' => string '4f128b2e6930f31137081950' (length=24)               'call_letters' => string 'KSEO' (length=4)               'channel_name' => string 'KSEO-Seoul' (length=10)               'bcast_channel' => int 101               'start_time_utc' => float 1326650400               'program_id' => string '99345001' (length=8)               'title' => string 'Seoul' (length=5)       16 =>          array           'text' => string 'KSEO' (length=4)           'items' =>              array               '_id' => string '4f128b2e6930f31137081951' (length=24)               'call_letters' => string 'KSEO' (length=4)               'channel_name' => string 'KSEO-Seoul' (length=10)               'bcast_channel' => int 101               'start_time_utc' => float 1326657600               'program_id' => string '99345001' (length=8)               'title' => string 'Seoul' (length=5)       17 =>          array           'text' => string 'KSEO' (length=4)           'items' =>              array               '_id' => string '4f128b2e6930f31137081952' (length=24)               'call_letters' => string 'KSEO' (length=4)               'channel_name' => string 'KSEO-Seoul' (length=10)               'bcast_channel' => int 101               'start_time_utc' => float 1326664800               'program_id' => string '99345001' (length=8)               'title' => string 'Seoul' (length=5)       18 => 
    my nested list code
    Code:
    Ext.setup({
        name: 'mapp',
        onReady: function() {
            Ext.define('Channels', {
                extend: 'Ext.data.Model',
            fields: [
                            {
                                name: "text",
                                type: "string"
                            }
                            ]
            });
    
            channelstore = Ext.create('Ext.data.TreeStore', {
                autoLoad: true,
                model: "Channels",
                defaultRootProperty: 'text',
                proxy: {
                    type: 'ajax',
                    url : '/channels/channelList',
                    reader: {
                        type: 'json',
                        root: 'text'
                    }
                }
            });
    
    
            channelPanel = Ext.create('Ext.NestedList', {
                fullscreen: true,
                title: 'Channels',
                displayField: 'text',
                store: channelstore
            });
    
                console.log(channelstore);
        }
    });
    Any input is greatly appreciated.

  2. Hi Essex,

    Here,

    i have attached the code.. it is working absolutely fine.. there is a possibility of u not getting the list working at all for json for a reason .. u might be not loading the same from server. Thats because of sandbox security ...
    Plus, have made some modifications..
    1 - added root : {} - This is a must / compulsary as there is a bug in 2.0 for nested list. Without this, the list of elements just doubles up.
    2 - in your data.. i noticed that there were no items .. other then the root. And all the items @end .. (last in the tree) needs to have 1 more attributed / element added to it... leaf = true.. Else it will continue with the node.. and will go in an endless loop. Thats the same thing u will notice for all the elements in the list .. except for element no 1

    Enjoy the code..
    I ran it on the server .. (apache) .. and it runs absolutely perfect .. without any issue.