Teknetik
Teknetik

Reputation: 178

EXTJS4 Xtemplate

As a bit of a begginer in the EXTJS world I was hoping for a bit of advise as I am a little stuck here:

I am pulling information from a store using Xtemplate.

var tpl = new Ext.XTemplate(
            '<tpl for=".">',
            '<p>{data.address}</p>',
            '<p>{data.ip}</p>',
            '</br>',
            '</tpl>'
        );

This displays a string for {data.address} as /domain/hub/servername.

I am trying to understand how I might beable to just display the "servername" section.

Reading the docs I see there you can use a function inside so I tried and failed with:

'<p>{[RegExp(".*/(.*)", data.address)]}</p>',

I am probably quite far off the mark there, like I say I am struggling with this one. Any advise welcome! thanks.

Upvotes: 0

Views: 1411

Answers (1)

Molecular Man
Molecular Man

Reputation: 22386

You can use combination of inline code and Template member functions like this:

var tpl = new Ext.XTemplate(
    '<tpl for=".">',
    '<p>{[this.getServerName(values.data.address)]}</p>',
    '<p>{data.ip}</p>',
    '</br>',
    '</tpl>',
    {
        getServerName: function(fulladdress) {
            return fulladdress.replace(/.*\//g, '');
        }
    }
);

Here is demo.

Upvotes: 3

Related Questions