1. #1
    Ext JS Premium Member
    Join Date
    Nov 2011
    Posts
    3
    Vote Rating
    0
    iericksonhp is on a distinguished road

      0  

    Default Unanswered: Nested XML using hasMany is not working for me

    Unanswered: Nested XML using hasMany is not working for me


    Hi,

    I'm having trouble parsing nested XML, and I've read the documentation for hasMany: http://docs.sencha.com/touch/2.2.0/#...iation.HasMany

    And using the forum post here as an example that is almost identical to my situation:
    http://www.sencha.com/forum/showthread.php?248047-Nested-XML-reader

    Yet no matter what I do this does not seem to be working for me. (I'm using latest ST 2.2.0)

    Here's what I have...

    XML file, test.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <groups>
            <group>
                    <grp_id>123</grp_id>
                    <member>
                            <cs_id>a</cs_id>
                            <name>a</name>
                            <login>a</login>
                    </member>
                    <member>
                            <cs_id>b</cs_id>
                            <name>b</name>
                            <login>b</login>
                    </member>
            </group>
            <group>
                    <grp_id>321</grp_id>
                    <member>
                            <cs_id>x</cs_id>
                            <name>x</name>
                            <login>x</login>
                    </member>
            </group>
    </groups>
    My model using hasMany to get at nested members, app/model/GroupsWithMembers.js:
    Code:
    Ext.define('NM.model.GroupsWithMembers', {
        extend:  'Ext.data.Model',
    
    
            config: { 
                fields: [
                    {name: 'grp_id'}
                ],
                hasMany: {model: 'NM.model.Members', name: 'members', associationKey: 'member'}                 
            }
    });
    Model for nested "members" app/model/Member.js:
    Code:
    Ext.define('NM.model.Members', {
        extend: 'Ext.data.Model',
            config:{
               idProperty: 'cs_id',        
               fields: [                 
                 {name: 'cs_id'},
                 {name: 'name'},
                 {name: 'login'},
               ]
        }
    });
    Model for GroupsWithMembers store, app/store/GroupsWithMembers.js:
    Code:
    Ext.define('NM.store.GroupsWithMembers', {
        extend: 'Ext.data.Store',
        requires: ['Ext.data.reader.Xml'],
        config: {
            model: 'NM.model.GroupsWithMembers',
            autoLoad: true,
            proxy: {            
                type: 'ajax',
                url: 'test.xml',            
                reader: {
                    type: 'xml',
                    rootProperty: 'groups',
                    record: 'group'
                }          
            },
            listeners:{            
                load: function(store, records, successful, operation, eOpts ) {                                
                    
                    var rec = store.getAt(0);
                    var mems = rec.members(); // STORE RETURNED HAS NO DATA/RECORDS ??
                    var memsdata = mems.getData();
    
                }
           }
       }
    });

    Any ideas to what I'm doing wrong?? Or why rec.members() returns an empty store??

    Thank you so much.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    853
    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


    I'm thinking this may be a bug in the Xml reader as it seems not to be translating the XML for the associated data into javascript. Using json reader this is working pretty good using something like:

    Code:
    {
        "groups" : [
            {
                "grp_id" : 123,
                "member" : [
                    {
                        "cs_id" : "a",
                        "name"  : "a",
                        "login" : "a"
                    },
                    {
                        "cs_id" : "b",
                        "name"  : "b",
                        "login" : "b"
                    }
                ]
            }
        ]
    }
    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.

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    2
    Vote Rating
    0
    phanikumar is on a distinguished road

      0  

    Default When Sencha Supports xml multiple level data?

    When Sencha Supports xml multiple level data?


    Lot of our backend servers return xml data, now its not possible to change them return json. So Does sencha planning to support xml multiple data, if so when it will be.

  4. #4
    Sencha User
    Join Date
    May 2009
    Posts
    4
    Vote Rating
    0
    kaleidos is on a distinguished road

      0  

    Default Same problem!

    Same problem!


    I confirm lot of backend servers return xml data,
    and for transform them in json this add server code... Why don't just support XML (multilevel)

  5. #5
    Sencha User
    Join Date
    Mar 2013
    Posts
    3
    Vote Rating
    1
    macsilber is on a distinguished road

      0  

    Default Same for me - any fix seems a trivial bug

    Same for me - any fix seems a trivial bug


    This works using similar associations
    <Task>
    ...
    <Baselines>
    <Baseline>
    <Number>0</Number>
    <Start>2013-04-08T08:00:00</Start>
    <Finish>2013-05-31T17:00:00</Finish>
    <Duration>PT320H0M0S</Duration>
    <Work>PT192H0M0S</Work>
    <Cost>1801407</Cost>
    </Baseline>
    <Baseline>
    <Number>1</Number>
    <Start>2013-04-08T08:00:00</Start>
    <Finish>2013-05-31T17:00:00</Finish>
    <Duration>PT320H0M0S</Duration>
    <Work>PT192H0M0S</Work>
    <Cost>1801407</Cost>
    </Baseline>
    </Baselines>
    </Task>
    This does not

    <Task>
    ...
    <Baseline>
    <Number>0</Number>
    <Start>2013-04-08T08:00:00</Start>
    <Finish>2013-05-31T17:00:00</Finish>
    <Duration>PT320H0M0S</Duration>
    <Work>PT192H0M0S</Work>
    <Cost>1801407</Cost>
    </Baseline>
    <Baseline>
    <Number>1</Number>
    <Start>2013-04-08T08:00:00</Start>
    <Finish>2013-05-31T17:00:00</Finish>
    <Duration>PT320H0M0S</Duration>
    <Work>PT192H0M0S</Work>
    <Cost>1801407</Cost>
    </Baseline>
    </Task>

    So if you wrapped yours in <members>...</members> it would work; but a lot of XML doesn't do that.

    If indeed you convert then most json converters interprets it correctly as below;

    "Baseline": [
    {
    "Number": "0",
    "Start": "2013-04-08T08:00:00",
    "Finish": "2013-05-31T17:00:00",
    "Duration": "PT320H0M0S",
    "Work": "PT1142H0M0S",
    "Cost": "8704280.33"
    },
    {
    "Number": "1",
    "Start": "2013-04-08T08:00:00",
    "Finish": "2013-05-31T17:00:00",
    "Duration": "PT320H0M0S",
    "Work": "PT1142H0M0S",
    "Cost": "8704280.33"
    }
    ],

  6. #6
    Sencha Premium Member jordandev's Avatar
    Join Date
    Feb 2011
    Location
    BC, Canada
    Posts
    41
    Answers
    1
    Vote Rating
    4
    jordandev is on a distinguished road

      0  

    Default


    Quote Originally Posted by macsilber View Post
    So if you wrapped yours in <members>...</members> it would work; but a lot of XML doesn't do that.
    Having this exact problem. The XML reader should be fixed to not require this.

  7. #7
    Sencha User
    Join Date
    Sep 2010
    Posts
    27
    Vote Rating
    2
    dusoft is on a distinguished road

      0  

    Default I have the same problem, but your solution doesn't work for me...

    I have the same problem, but your solution doesn't work for me...


    I am going grazy!..
    Please, can you help me?

    See my post..

    http://www.sencha.com/forum/showthre...g-nested-json-
    Model-and-hasMany-association.