Inline code in xtemplate

http://stackoverflow.com/questions/10851683/extjs4-xtemplate

HTML

<link rel="stylesheet" href="http://dev.sencha.com/deploy/ext-4.0.7-gpl/resources/css/ext-all.css">

JavaScript

Ext.create('Ext.data.Store', {
    id:'myStore',
    fields: [
        { name:'ip', type:'string' },
        { name:'address', type:'string' }
    ],
    data: [
        { ip:'127.0.0.1', address:'ASAHI CHEMICAL MICRO SYST [JP]' },
        { ip:'127.0.0.2', address:'OSRAM OPTO SEMICONDUCTORS GMBH [DE]' }
    ]
});

var tpl = new Ext.XTemplate(
    '<tpl for=".">',
    '<p class="addr">{[this.getServerName(values.address)]}</p>',
            '<p>{ip}</p>',
            '</br>',
            '</tpl>',
    {
        getServerName: function(v) {
            //return fulladdress.replace(/.*\//g, '');
            
            var foo = v.match(/ \[([A-Z]+)\]/);
            var cc  = foo[1];  
                        
            var i = v.lastIndexOf(' [');
            var n = v.substring(0, i-1);
                        
            return Ext.String.format('<img src="http://127.0.0.1:8080/projects/PatentPulse/resources/img/flags/{0}.bmp">&nbsp; ', cc) + n;
        }
    }
);

Ext.create('Ext.view.View', {
    store: Ext.data.StoreManager.lookup('myStore'),
    tpl: tpl,
    itemSelector: 'p.addr',
    renderTo: Ext.getBody()
});