1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    8
    Vote Rating
    0
    testmacher is on a distinguished road

      0  

    Default Answered: XML Nested Mapping

    Answered: XML Nested Mapping


    Hello Guys,


    I have a problem with XML reading in ST 2.1.


    From the Server, i get something like this:


    Code:
      ...  
    <node>
        <test id="774">TestText</test>
        <test id="775">TestText</test>
    </node> ...

    I want to load this into a Store but I have a problem with the mapping.


    I have this model:


    Code:
      
    Ext.define('SubModel', {    
        extend:'Ext.data.Model',    
        config:{          
            fields:[          
                {name:'test_id', mapping:'@id', type:'int'},  
                {name:'text', mapping:'/', type:'string'}    
                ],        
            belongsTo:{model:'ParentModel'}    
        }  
    });

    The problem is, I get the "test_id", but the mapping for the "text" doesn't seem to work.


    In the parentmodel I have this:


    Code:
      
    {
        type:'hasMany',  
        associatedName:'node',  
        associatedModel:'SubModel',  
        associationKey:'node',  
        reader: {type:'xml',record:'node > test'}  
    },

    If I only do "record:'node' ", only one "test"-entry is in the store.


    I hope you can help me.


    Thank You.


    testmacher

  2. You have associationKey to the node, why not have record set to 'text'?

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


    You have associationKey to the node, why not have record set to 'text'?
    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.

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    8
    Vote Rating
    0
    testmacher is on a distinguished road

      0  

    Default


    Thank you!!!
    That worked so far

    But I also have another question.

    In my xml, there is a "Medias" node looking like this:
    PHP Code:
    <medias>
    <
    media id="12461" src="/getMedia?id=12461"/>
    <
    media_t id="12461" src="/getMedia?id=12461&thumbnail=true"/>
    <
    media id="12462" src="/getMedia?id=12462"/>
    <
    media_t id="12462" src="/getMedia?id=12462&thumbnail=true"/>
    <
    media id="12463" src="/getMedia?id=12463"/>
    <
    media_t id="12463" src="/getMedia?id=12463&thumbnail=true"/>
    </
    medias
    Is there a possibility to parse this into just one Model:

    PHP Code:
    Ext.define('Model', {
        
    extend:'Ext.data.Model',

        
    config:{
            
    idProperty:'media_id',
            
    fields:[
                {
    name:'media_id'mapping:'@id'type:'auto'},
                {
    name:'media_src'mapping:'@src'type:'string'},
                {
    name:'media_t_src'mapping:'@src'type:'string'}
            ]
        }
    }); 
    At the Moment, I use two Models for this...
    Unfortunately, the API is invariable and sometimes, there is a bigger difference between the src of "media" and the associated "media_t" in the XML.

    Thank you.

    Testmacher

Thread Participants: 1