Hybrid View

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext User
    Join Date
    Sep 2010
    Posts
    21
    Vote Rating
    0
    Nostromo is on a distinguished road

      0  

    Default [FIXED-583] nested xml / complex xml, cant get associations to work

    [FIXED-583] nested xml / complex xml, cant get associations to work


    Hi all,

    There are users who can have books. so I came up with the following simple XML.
    PHP Code:
    <?xml version="1.0" encoding="ISO8859-1" ?>
    <users>
      <user>
        <userid>1</userid>
        <username>Mickey Mouse</username>    
        <books>
          <book>
            <bookname>book a</bookname>
            <pages>723</pages>
            <score>55</score>
          </book>
          <book>
            <bookname>book b</bookname>
            <pages>434</pages>
            <score>86</score>
          </book>
          <book>
            <bookname>book c</bookname>
            <pages>123</pages>
            <score>37</score>
          </book>
        </books>    
      </user>
    </users>
    And the following method for loading the users and books in to the store and list:
    PHP Code:

    Ext
    .regModel('Book',{
          
    fields:[
          {
    name:'bookname',type:'string'},
          {
    name:'pages',type:'int'},
          {
    name:'score',type:'int'}
        ]
    })

    Ext.regModel('User',{
          
    fields:[
          {
    name:'userid',type'int'},
          {
    name:'username',type:'string'}      
        ],
        
    associations:[
          {
    type:'hasMany',model:'Book',name:'books'}
        ]
    });

     

    var 
    HitrateStore = new Ext.data.Store({
        
    model'User',
        
    proxy: {
            
    type'ajax',
            
    url'./src/combi.xml',
            
    reader: {
                
    type'xml',
                
    record:'user'
            
    }
        },
        
    listeners: {      
            
    load: function(storerecordssuccess){
              if(
    success)
              {
                  if(
    debugMode)console.log('successfull loaded xml from server',records);
                  
    console.log(HitrateStore)
              }
            }
        }
    });
     

    var 
    testtpl '<div class="graph">{username}</div>';

    var list = new 
    Ext.List({
        
    cls:'lijst',
        
    itemTpl:'<tpl for=".">'testtpl +'</tpl>',
        
    itemSelector'div.graph',
        
    singleSelectfalse,
        
    grouped     false,
        
    indexBar    false,
        
    layout'card',    
        
    storeHitrateStore,
        
    floating     true,
        
    width        350,
        
    height       370,
        
    centered     true,
        
    modal        true,
        
    hideOnMaskTapfalse,
        
    listeners: {
                    
    beforeactivate: function(c)
                    {   
                      
    HitrateStore.load();
                    }
                  }
    }); 
    I dont get an error message. The users get loaded but their books dont get loaded....
    Dont know where the problem is....

    I also have updated to Sencha Touch 0.99....

    Someone had the same problem or got an awnser?

    Kind regards,

  2. #2
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    I'll see if I can get this replicated and fixed for the next release. Sorry for the inconvenience on this one - as demand is so low for XML-powered apps on mobile it has taken a back seat to JSON development
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  3. #3
    Ext User
    Join Date
    Oct 2010
    Posts
    15
    Vote Rating
    0
    Plastic is on a distinguished road

      0  

    Default


    any news with this issue on 1.0RC..

    Have you solved the association problem???

  4. #4
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Moved this to the bugs forum and opened a ticket. This was lost in the conference mayhem last week - just as a heads-up that's less likely to happen if you report bugs in the bugs forum.

    We're looking at putting out a 1.0.1 shortly so I'll try to get this in for then.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  5. #5
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    9
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    I've just added a patch to enable this to work. Currently, each Model is going to need an XML Reader to be able to parse the data properly. In your case you'll need something like this:

    Code:
    Ext.regModel('Book',{ 
        fields:[ 
            {name:'bookname',type:'string'}, 
            {name:'pages',type:'int'}, 
            {name:'score',type:'int'} 
        ],
        
        proxy: {
            type: 'memory',
            reader: {
                type: 'xml',
                root: 'books',
                record: 'book'
            }
        }
    });
    
    Ext.regModel('User',{ 
        fields:[ 
            {name:'userid',type: 'int'}, 
            {name:'username',type:'string'}       
        ], 
        
        hasMany: {model: 'Book', name: 'books'},
        
        proxy: {
            type: 'ajax',
            url : 'path/to/your.xml',
            reader: {
                type: 'xml',
                root: 'users',
                record: 'user'
            }
        }
    });
    If you're currently putting your initial Proxy on the Store instead (looks like you are), you can keep it there if you prefer. Note that you have to set a Proxy on the Book model to set up the Reader that will parse that nested XML. You need to make this a MemoryProxy for now as it will be passed associated data by the nested loading of the User model.

    I'm not totally sold on this as an API but I have it tested and confirmed working. I'll revisit it later to see if we can make this a bit easier. These changes will be present in the next release.
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  6. #6
    Ext User
    Join Date
    Oct 2010
    Posts
    15
    Vote Rating
    0
    Plastic is on a distinguished road

      0  

    Default


    Do you mean it already works or it will work as soon as the next release will be released?

Similar Threads

  1. Nested Xml with associations?
    By kaine in forum Sencha Touch 1.x: Discussion
    Replies: 3
    Last Post: 15 Feb 2012, 3:46 AM
  2. [FIXED-583] nested xml / complex xml, cant get associations to work
    By Nostromo in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 19 Nov 2010, 7:39 AM
  3. Replies: 1
    Last Post: 5 May 2009, 8:54 AM
  4. Nested View Objects/Nested Xml collections
    By dwebsubmit in forum Ext 1.x: Help & Discussion
    Replies: 10
    Last Post: 11 Oct 2007, 2:30 PM

Thread Participants: 9