1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    410
    Vote Rating
    2
    parky128 is on a distinguished road

      0  

    Default Question about XTemplate usage in a view config

    Question about XTemplate usage in a view config


    Hi,

    Is it possible to get a reference to the application instance from a member function of an XTemplate in a view config? Sorry, thats quite a mouthful there! Here is some code:

    Code:
    Ext.define('PinpointersTouch.view.UnitList', {
        extend: 'Ext.List',
        xtype: 'unitslist',
        config: {
            fullscreen: true,
            itemTpl: new Ext.XTemplate(
                    '<ul id="unitList">',
                        '<tpl for=".">',
                            '<li>',
                                '<table width="100%" cellspacing="0">',
                                    '<tr>',
                                        '<td style="width:30px; text-align:center">{[this.getUnitIcon(values.id)]}</td>',
                                        '<td valign="middle"> - {UnitName}</td>',
                                    '</tr>',
                                '</table>',
                            '</li>',
                        '</tpl>',
                    '</ul>',
                    {
                        getUnitIcon: function(untID) {
                            //var iconNum = this.application.getTrackingListStore().getById(untID).data.MapIcon;
                            
                            //TO Do: Can I get a reference to the application instance from in here???
                        }
                    }),
            store: 'CurrentGrid'        
        }
    });
    I need to look up some values in another store in my application based on a value being passed into the XTemplate member function.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,212
    Vote Rating
    858
    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


    Yes and no.

    By default, the application instance isn't cached anymore so in your launch method you can cache it on your namespace:

    Code:
    Ext.application({
        name : 'MyApp',
    
        launch : function() {
            MyApp.app = this;
        }
    });
    Now anywhere in your code you can access the application instance from MyApp.app.
    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 - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    ^^^

    Which is a bug in PR2, and will be fixed before GA. But for now, that fixes it.
    Sencha Inc.
    Robert Dougan - @rdougan
    Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.

  4. #4
    Touch Premium Member
    Join Date
    Nov 2011
    Posts
    37
    Vote Rating
    0
    bortron5000 is on a distinguished road

      0  

    Default


    Couldn't you also use Ext.getStore() and then filter it by the id property, or use findExact() if the id is unique? Or am I way off base...