Extracting data from XML I want to preprocess one before sending it as a variable to template. A stackoverflow fellow pointed me to Ext.Xtemplate and that is close to do the job.
In each of my records I have a value “coordinates” of this pattern : 2.342556,48.873802,0.000000
3 items separated with comma. I need the first and the second.
So I decided to split but It doesn’t work.
My attempt so far (trying to display only one value for testing purposes)
Code:
var tpl = new Ext.XTemplate(
'<div>{name}<br>{[ values.coordinates.split(',')[1] ]}</div>'
);
This echo nothing.
If I display the [0] column of the array it displays the whole string, unsplited. This means that it didn’t parse the comma.
If I split with something else it works (for example with an integer)
Code:
var tpl = new Ext.XTemplate(
'<div>{name}<br>{[ values.coordinates.split(6)[1] ]}</div>'
);
I tried to split with the point (‘.’) but it throw an error (“unexpected string”)
Maybe I should use a template member function but the example in the doc are not very clear for me.
Thanks for your help,
Julius
You need to escape the single quotes or use double quotes like so:
Otherwise your call will be like this:
I.E. you pass 2 string parameters instead of 1.
A similar problem would be with this:
Except this would throw a syntax error because there is no coincidential comma in there.