PDA

View Full Version : Problem with using XTemplate - how to pass arguments



paweluz
21 Mar 2011, 4:10 AM
Hi

I am using Ext.XTemplate in my application for changing the way of displaying of row in Grid. Depends on given data row may be displayed in defferent way. My code looks like that:


var myTemplate = new Ext.XTemplate(
'<tpl if="this.hasData(values) == true ">',
'<tpl for="values.value">',
'<tpl if="xindex === 1">',
'<tpl if="this.ifShouldAddValues(values) == true ">',
'<U><a id="{name}" onclick="test.function1(\'{name}\')">{name}</a></U>',
'</tpl>',
'<tpl if="this.ifShouldAddValues(values) == false ">',
'<U><a id="{path}" onclick="test.function2({path})">{path}</a></U>',
'</tpl>',
'</tpl>',
'<tpl if="xindex != 1">',
'<tpl if="this.ifShouldAddValues(values) == true ">',
', <U><a id="{name}" onclick="test.function1(\'{name}\')">{name}</a></U>',
'</tpl>',
'<tpl if="this.ifShouldAddValues(values) == false ">',
', <U><a id="{path}" onclick="test.function2({path})">{path}</a></U>',
'</tpl>',
'</tpl>',
'</tpl>',
'</tpl>',{
compiled: true,
ifShouldAddValues: function(values){
if (values.name)
return true
else
return false
},
disableFormats: true,
hasData: function (valueRoot) {
return true
}
});Problem is that I can not pass argument in my onclick function. If I do this like that:
function1(\'{name}\') - the parameter is sent and it is ok
function2(\'{path}\') - the parameter is sent without slashes. This is a path to some file, and when I do like that slashes are missing. So .e.g if I got path:
d:/mydir/myfile.xml the result is d:mydirmyfile.xml
If I do function2({path}) (like many examples on the Internet ) I got an error:

missing ) after argument list
[Stop at this error] function2(d:/mydir/myfile.xml)

I have no idea why is that. To make it work I used not really not nice way of getting that value like that:

...


'<tpl if="this.ifShouldAddValues(values) == false ">',
', <U><a id="{path}" onclick="function2(this.id)">{path}</a></U>',
'</tpl>', ...
this.id takes the id of div. I have no idea how I can make it work in other way. Can anyone please help me on that? Am I able to pass hole object to that onClick function as well ?

Regards,
Pawel