1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
    mhulse is on a distinguished road

      0  

    Default Unanswered: Render hasMany Association in XTemplate

    Unanswered: 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    900
    Answers
    3574
    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


    Using the getter to get the hasMany, it returns a Store so it doesn't really allow for getting associated data.
    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.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
    mhulse is on a distinguished road

      0  

    Default


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

Thread Participants: 1