1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    1
    Vote Rating
    0
    pluto_44 is on a distinguished road

      0  

    Default How to display sub categories

    How to display sub categories


    I have recently made an application where few categories are displayed. But I also want the sub categories to be displayed on clicking the parent categories menu. However I have used the following code to display the categories.
    My store code is----

    Ext.define('listdemo.store.Sections', {
    extend : 'Ext.data.Store',


    config : {
    autoLoad: true,
    model: 'listdemo.model.Sections',

    proxy:{
    type : 'ajax',
    url:'http://localhost/catt.php',

    reader:{
    type:'json',
    rootProperty:'categories'
    }

    }
    }
    });

    The model code is----

    Ext.define('listdemo.model.Sections', {
    extend: 'Ext.data.Model',

    config: {
    fields: ['categories_id', 'categories_name','subcategories'],


    }
    });
    And the view is-----

    Ext.define('listdemo.view.Main',{
    extend: 'Ext.NestedList',
    xtype:'main',
    requires: [
    'Ext.TitleBar',
    'Ext.dataview.List',
    'Ext.data.Store',
    'Ext.dataview.NestedList'
    ],

    config:{
    title: 'Categories',
    //store:'Sections',
    items:[
    {
    xtype:'list',
    itemTpl:'{categories_name}',
    title:'Categories',
    store:'Sections',

    }
    ]
    }
    });

    I have a php file which returnes as follows----

    {"categories":[{"categories_id":"1","categories_name":"Hardware","subcategories":[{"categories_id":"4","categories_name":"Graphics Cards"},{"categories_id":"5","categories_name":"Printers"},{"categories_id":"6","categories_name":"Monitors"},{"categories_id":"7","categories_name":"Speakers"},{"categories_id":"8","categories_name":"Keyboards"},{"categories_id":"9","categories_name":"Mice"},{"categories_id":"16","categories_name":"Memory"},{"categories_id":"17","categories_name":"CDROM Drives"}]},{"categories_id":"2","categories_name":"Software","subcategories":[{"categories_id":"18","categories_name":"Simulation"},{"categories_id":"19","categories_name":"Action"},{"categories_id":"20","categories_name":"Strategy"}]},{"categories_id":"3","categories_name":"DVD Movies","subcategories":[{"categories_id":"10","categories_name":"Action"},{"categories_id":"11","categories_name":"Science Fiction"},{"categories_id":"12","categories_name":"Comedy"},{"categories_id":"13","categories_name":"Cartoons"},{"categories_id":"14","categories_name":"Thriller"},{"categories_id":"15","categories_name":"Drama"}]}]}

    Thanks in advance.....

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,620
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Why not use NestedList and TreeStore?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Thread Participants: 1