Results 1 to 3 of 3

Thread: Render hasMany Association in XTemplate

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
      0  

    Default Render hasMany Association in XTemplate

    The XTemplate in the following code renders the parent object (user), but not the children (addresses). Can someone point me in the right direction? Thanks!

    Code:
    Ext.setup({
        icon: 'icon.png',
        tabletStartupScreen: 'tablet_startup.png',
        phoneStartupScreen: 'phone_startup.png',
        glossOnIcon: false,
        onReady: function() {
    
    
            User = Ext.regModel('User', {
                fields: [
                    {name: 'id',        type: 'int'},
                    {name: 'email',     type: 'string'},
                    {name: 'password',  type: 'password'},
                    {name: 'addresses', type: 'array' }
                ],
                hasMany: {model: "Address", name: "address"}
            });
    
    
            Address = Ext.regModel('Address', {
                fields: [
                    {name: 'id',        type: 'int'},
                    {name: 'userId',    type: 'int'},
                    {name: 'type',      type: 'string'},
                    {name: 'street',    type: 'string'}
                ],
                belongsTo: {model: 'User', name: 'user' }
            });
    
    
            var userData = {
                users: [
                    {id: 1, email: 'test1@here.com', password: 'secret1'},
                    {id: 2, email: 'test2@here.com', password: 'secret2'},
                    {id: 3, email: 'test3@here.com', password: 'secret3'}
                ]
            };
    
    
            var addressData = {
                addresses: [
                    {id: 1, userId: 1, type: 'home', street: '123 Main St.'},
                    {id: 2, userId: 1, type: 'work', street: '3328 Primrose Lane.'},
                    {id: 3, userId: 2, type: 'home', street: '47 Baltic Ave.'},
                    {id: 4, userId: 3, type: 'home', street: '757 Unicorn Place'},
                    {id: 5, userId: 3, type: 'work', street: '10 Claire Rd.'}
                ]
            };
    
    
            var addressStore = new Ext.data.Store({
                autoLoad: true,
                model: 'Address',
                data: addressData,
                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'json',
                        root: 'addresses'
                    }
                }
            });
    
    
            
            var dview = new Ext.DataView({
                store: new Ext.data.Store({
                    autoLoad: true,
                    model: 'User',
                    data: userData,
                    proxy: {
                        type: 'memory',
                        reader: {
                            type: 'json',
                            root: 'users'
                        }
                    }
                }),
    
    
    
    
                tpl: new Ext.XTemplate(
                    '<p>Users</p>',
                    '<tpl for=".">',
                        '<div class="lineitem">id: {id} {email} </div>',
                        '<ul>',
                            '<tpl for="Address">',
                                '<li>{type} {street}</li>',
                            '</tpl>',
                        '</ul>',
                    '</tpl>'
                ),
                
                fullscreen: true,
                itemSelector: 'div.lineitem'
    
    
            });
        }
    });

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Using the getter to get the hasMany, it returns a Store so it doesn't really allow for getting associated data.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
      0  

    Default

    Given the XTemplate I've created, is there a way to loop through the child records for each parent?

Posting Permissions

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