PDA

View Full Version : [Solved] Need more reference in XTemplate



steffenk
12 Apr 2010, 9:34 AM
When i use a subfunction in XTemplate i need access to other fields of applied data. Is there a possibility?

Example:

return new Ext.XTemplate(
'<tpl for=".">',
'<span class="single-main-category-subcategory-kicker">{subcategory}</span>',
'<span class="single-main-category-subcategory-title">{title}</span>',
'<div class="single-article-author">von {author}</div>',
'<tpl if="files != \'\'">',
'{files:this.displayFile}',
'</tpl>',
'</tpl>',
{
displayFile: function(value) {
// here i need to access other fields, eg {title}
}
});

with debugging i didn't saw a possibility, as there is no reference to the applied data.
Any idea? Or is this a missing flexibility? Is there a way to get more than one argument to the inside function?

elishnevsky
12 Apr 2010, 10:28 AM
return new Ext.XTemplate(
'<tpl for=".">',
'<span class="single-main-category-subcategory-kicker">{subcategory}</span>',
'<span class="single-main-category-subcategory-title">{title}</span>',
'<div class="single-article-author">von {author}</div>',
'<tpl if="files != \'\'">',
'{[this.displayFile(values)]}',
'</tpl>',
'</tpl>',
{
displayFile: function(values) {
// here i need to access other fields, eg {title}
var title = values.title;
// access other fields the same way
// return value will be displayed in the template
}
}
);

steffenk
12 Apr 2010, 10:57 AM
Hi Eugene,

this is cool, thank you very much!

From where did you got the information about this solution? I didn't found anything about that.

elishnevsky
12 Apr 2010, 11:06 AM
From the documentation: http://www.extjs.com/deploy/dev/docs/?class=Ext.XTemplate&member=XTemplate and my head :)

steffenk
12 Apr 2010, 11:13 AM
Ahrgg :)

I read it x times but seems i missed this big sentence:

Anything between {[ ... ]} is considered code to be executed in the scope of the template.

Now there is no limitation, thanks again :)