Results 1 to 4 of 4

Thread: Loading nested XML data into hasmany model

  1. #1
    Sencha User
    Join Date
    Mar 2008
    Posts
    7

    Default Loading nested XML data into hasmany model

    Hello,

    I am struggling for quite a while on how to load fully following xml into my model. I can load the customer with attributes and also the parameteres separately. But I would like to load them within one Ajax call over the hasMany relationship or other recommended association. The main parameteres always seem to work but the other parameters I cannot access afterwards over the hasMany association. I am especially interested in the "parameters" sections once the overall model is loaded. Any recommendations on how to load nested data into nested models is highly welcomed. Thanks in advance:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <customer xmlns="http://www.testdomain.com/product/model">
    <statusKey>ACTIVE</statusKey>
    <activationDate>2015-02-02T04:17:32+01:00</activationDate>
    <lastModified>2015-02-02T04:18:06+01:00</lastModified>
    <overdueBalance>0</overdueBalance>
    <accountBalance>0</accountBalance>
    <additionalDetails/>
    <customerTypeKey>ENTERPRISE</customerTypeKey>
    <customerAttributes>
    <firstName>Leto</firstName>
    <lastName>Atreides</lastName>
    <entityTypeKey>INDIVIDUAL</entityTypeKey>
    <businessName>CHOAM Corp.</businessName>
    <commercialRegistrationNumber>123456</commercialRegistrationNumber>
    <parameters>
    <parameter>
    <key>Param1</key>
    <value>Vladimir Harkonnen</value>
    </parameter>
    <parameter>
    <key>Param2</key>
    <value>+44</value>
    </parameter>
    <parameter>
    <key>Param3</key>
    <value>LetoAtreides</value>
    </parameter>
    </parameters>
    </customerAttributes>
    </customer>
    ----

    Ext.define('myTestModel', {
    extend: 'Ext.data.Model',
    uses: [
    'MyTestModelParameter'
    ],
    idProperty: 'idTestModel',
    fields: [
    {name : 'idTestModel', type:'auto'},
    {name : 'statusKey', type : 'auto'},
    {name : 'activationDate', type : 'auto'},
    {name : 'lastModified', type : 'auto'},
    {name : 'overdueBalance', type : 'auto'},
    {name : 'accountBalance', type : 'auto'},
    {name : 'customerTypeKey', type : 'auto'},
    {name : 'firstName', type : 'auto'},
    {name : 'lastName', type : 'auto'},
    {name : 'entityTypeKey', type : 'auto'},
    {name : 'businessName', type : 'auto'},
    {name : 'commercialRegistrationNumber', type : 'auto'}
    ],
    hasMany : [
    {model:'MyTestModelParameter', name: 'getMyTestModelParameters', foreignKey: 'idTestModelParam' }
    ],
    proxy: {
    type: 'ajax',
    url: 'http://localhost:1841/app/data/customers_28.xml',
    reader: {
    type: 'xml',
    record: 'customer',
    rootProperty: 'customer'
    }
    }
    });

    Ext.define('MyTestModelParameter', {
    extend: 'Ext.data.Model',
    idProperty: 'idTestModelParam',
    fields: [
    {name : 'idTestModelParam', type:'auto'},
    {name : 'key', type : 'auto'},
    {name : 'value', type : 'auto'}
    ]
    });


    Ext.define('myTestModelStore',{
    extend: 'Ext.data.Store',
    model: 'myTestModel',
    listeners : {
    load : function(store) {
    console.log("Store Load Called");
    console.log(store.first());
    console.log(store.first().getMyTestModelParameters().load());
    console.log(store.first().getMyTestModelParameters())
    console.log(store.first().get("firstName"));
    console.log(store.first().getData());
    //console.log(store.getProxy().getData());
    },
    write : function(store) {
    console.log("Store Write Called");
    //console.log(store.getProxy().getData());
    }
    }
    });

  2. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Hi--

    If you give your hasMany definition a reader, you can tell it where to find the association data. Please see the Fiddle below.

    Thanks!
    Joel


  3. #3
    Sencha User
    Join Date
    Mar 2008
    Posts
    7

    Default Thanx & Documentation for Associations and model relationships for EXT JS 5.x require

    Hello,

    thankx a lot. Great help. Somehow I have struggled for the last 10 days with it and I would not have any idea that I can add a reader in this position there.

    So I switched to JSON which surprisingly somehow worked out of the box with my model without the need to attach additional readers.

    Would be great if you could add some more examples and deeper documentation especially in the area of associations and model relationships, loading of nested JSON and xmld data etc. Because this is such an overlooked but fundamental topic for Enterprise applications.

    Thanks a lot,

    Kind Regards,

    Martin

    PS: I love ExtJS !

  4. #4
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Cool, glad it helped!

    If you have additional questions about associations, please post back.

    Thanks!
    Joel

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •