1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    13
    Vote Rating
    0
    rainierwolfcastle is on a distinguished road

      0  

    Default Unanswered: Nested XML, hasmany, store

    Unanswered: Nested XML, hasmany, store


    Hey all,

    got some problems with nested XML in Sencha Touch 2. My code is based on an example with JSON: http://www.sencha.com/forum/showthre...ON-and-hasMany

    I'm getting "There are 0 matches" on the console.
    So what do I have to change on my code to get the "matches"?

    data.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <jobs>
        <job>
            <jobId>334</jobId>
            <phone>245234</phone>
            <matches>
                <match>
                    <matchId>43</matchId>
                    <status>M_NEW"</status>
                </match>
                <match>
                    <matchId>42</matchId>
                    <status>M_NEW"</status>
                </match>
                <match>
                    <matchId>45555</matchId>
                    <status>M_NEW"</status>
                </match>
            </matches>        
        </job>
        <job>
            <jobId>406</jobId>
            <phone>55333555</phone>
            <matches>
                <match>
                    <matchId>46789</matchId>
                    <status>M_NEW"</status>
                </match>
            </matches>
        </job>
    </jobs>
    MatchModel
    Code:
    Ext.define('Simplestore9.model.MatchModel', {
        extend : 'Ext.data.Model',
        config : {
            idProperty : 'matchId',
            fields     : [
                'matchId',
                'status'
            ]
        }
    });
    JobModel
    Code:
    Ext.define('Simplestore9.model.JobModel', {
        extend: 'Ext.data.Model',
        
        config: {
            fields  : [
                {
                    name : 'jobId',
                    type : 'int'
                },
                {
                    name : 'phone'
                }
            ],
            hasMany : [
                {
                    model          : 'Simplestore9.model.MatchModel',
                    name           : 'matches',            
                    associationKey : 'matches'              
                }
            ]
        }
    });
    Loading the Store:
    Code:
    var store = Ext.create('Ext.data.Store', {
                model: 'Simplestore9.model.JobModel',
                proxy: {
                    type   : 'ajax',
                    url    : 'resources/data/data.xml',
                    reader: {
                        type: 'xml',
                        record: 'job',
                        rootProperty: 'jobs'
                    }
                },
                listeners : {
                    load : function(store) {
                        var rec      = store.getAt(0);                                   
                         var matches  = rec.matches();
                             
                         console.log('There are ' + matches.getCount() + ' matches');
                                        
                    }
                }
            });
            
             store.load();

  2. #2
    Sencha User
    Join Date
    Jul 2012
    Posts
    13
    Vote Rating
    0
    rainierwolfcastle is on a distinguished road

      0  

    Default


    any idea?

  3. #3
    Sencha User bluehipy's Avatar
    Join Date
    Mar 2010
    Location
    Romania
    Posts
    604
    Answers
    66
    Vote Rating
    26
    bluehipy will become famous soon enough bluehipy will become famous soon enough

      0  

    Default


    Some idea..
    The relation store, doesn t nkow what to consider as record. In the hasMany association definition you could / should pass some store settings saying that the record needed is 'match'.


    http://docs.sencha.com/touch/2-0/#!/api/Ext.data.association.HasMany-cfg-store


    http://docs.sencha.com/touch/2-0/#!/api/Ext.data.association.HasMany-cfg-storeConfig



    Maybe


    hasMany : [ { model : 'Simplestore9.model.MatchModel', name : 'matches', associationKey : 'matches', store:{ proxy:{ reader:{ type:'xml', record:'match' } } } } ]

    Anyway the idea is the association cant' gueess it has to look inside the 'match' node


    Also ou might need in there:

    var matches = rec.matches();

    matches.load();

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar