1. #1
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
    Yo074 is on a distinguished road

      0  

    Default Unanswered: XML TreeStore multilevel issue

    Unanswered: XML TreeStore multilevel issue


    Hello,

    I'm quite new to Sencha Touch and after few hours of searching, I decided to ask for help!

    I'm currently facing the following issue:

    let's consider the following XML file (categories.xml) :

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <categories>
        <category>
            <name>Cat1</name>
            <category>
                <name>SubCat1-1</name>
                <category>
                    <name>SubSubCat1-1</name>
                </category>
            </category>
            <category>
                <name>SubCat1-2</name>
            </category>
        </category>
        <category>
            <name>Cat2</name>
            <category>
                <name>SubCat2-1</name>
                <category>
                    <name>SubSubCat2-1</name>
                </category>
            </category>
            <category>
                <name>SubCat2-2</name>
            </category>
        </category>
    </categories>
    Here is my model :

    Code:
    Ext.define('touchme.model.Category', {    extend: 'Ext.data.Model',
        
        config: {
            fields: ['name'],
            associations: [{
                type: 'hasMany',
                model: 'touchme.model.Category',
                name:'categories',
                associationKey: 'categories',
                reader: {
                    type: 'xml',
                    rootProperty: 'categories'
                }
            }]
        }
    });
    And here is the store :

    Code:
    Ext.define('touchme.store.Categories', {    extend : 'Ext.data.TreeStore',
        require: 'touchme.model.Category',
        config : {
            model     : 'touchme.model.Category',
            storeId   : 'categoriesStore',
            nodeParam : 'category',
            proxy     : {
                type   : 'ajax',
                url    : 'categories.xml',
                reader : {
                    type : 'xml',
                    rootProperty: 'categories',
                    record: 'category'
                }
            },
            autoLoad: true
        }
    });
    I then created a nestedList view :

    Code:
    Ext.define('touchme.view.TestNestedList', {    extend : 'Ext.dataview.NestedList',
        alias  : 'widget.nestedList',
        title  : 'Test Categories',
        
        config : {
            store    : 'categoriesStore',
        
            itemTpl: ['<div>{name}</div>']
        } 
    });
    Problem is, the nested list is not showing correctly,

    Instead of having :

    Code:
    Cat1
    |->SubCat1-1
    |   |->SubSubCat1-1
    |->SubCat1-2
    Cat2
    |->SubCat2-1
    |   |->SubSubCat2-1
    |->SubCat2-2
    I have the following:

    Code:
    Cat1
    SubCat1-1
    SubSubCat1-1
    SubCat1-2
    Cat2
    SubCat2-1
    SubSubCat2-1
    SubCat2-2
    As anyone already faced this issue?

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,684
    Vote Rating
    435
    Answers
    3111
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    That's because of your record config in your reader, it will get all category nodes not just the one level.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

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

  3. #3
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
    Yo074 is on a distinguished road

      0  

    Default


    Hi mitchellsimoens and thanks for your answer.

    Removing the 'record' element from the treestore reader cause the following error :

    [ERROR][Ext.data.reader.Reader#readRecords] Record is a required parameter

    Any thoughts?

  4. #4
    Sencha User
    Join Date
    Feb 2013
    Posts
    3
    Vote Rating
    0
    Yo074 is on a distinguished road

      0  

    Default


    Hi,

    I kept searching but not found any solution.
    Anyone has a clue?

    Thanks,

Tags for this Thread