PDA

View Full Version : using inline javascript code in Xtemplates



utkarshk.leeway
24 Nov 2011, 11:47 AM
hi,

i want yo use some of my custom code to format data coming from store to be displayed using Xtemplates. like i want to know if i can assign value of {comment_on} to some variable or not??

example if i try doing this it gives error {[var dattaa = {comment_on}]} {[niceTime(dattaa)]} - nice time is my custom function to format date ..

however it works fine if i use it this ways {[niceTime("2011-11-2T14:12:07")]}

please suggest how can i format my date using my custom functions.

thanks in advance
Regards
UT

tobiu
24 Nov 2011, 2:58 PM
study the examples:
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.XTemplate

like:


var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Kids: ',
'<tpl for="kids">',
'<tpl if="this.isGirl(name)">',
'<p>Girl: {name} - {age}</p>',
'</tpl>',
// use opposite if statement to simulate 'else' processing:
'<tpl if="this.isGirl(name) == false">',
'<p>Boy: {name} - {age}</p>',
'</tpl>',
'<tpl if="this.isBaby(age)">',
'<p>{name} is a baby!</p>',
'</tpl>',
'</tpl></p>',
{
// XTemplate configuration:
disableFormats: true,
// member functions:
isGirl: function(name){
return name == 'Sara Grace';
},
isBaby: function(age){
return age < 1;
}
}
);


you also have "values" available in the methods. like values.age etc.