PDA

View Full Version : XTemplate Values Object



jbeaven
21 Aug 2013, 5:31 AM
Does anyone know of a good way to find out what this object is/contains?

Every time I have to deal with XTemplates I invariably find myself trying to figure out what fields it's magically possible to use.

It's quite frustrating. So does anyone have a simple way they find out what their XTemplates are expecting?

willigogs
21 Aug 2013, 6:03 AM
I'm not sure I'm understanding your issue? The XTemplate should be able to insert any values which are available in the passed record.

Could you give a code example of your issue?

jbeaven
21 Aug 2013, 6:09 AM
Not really.

We have literally 10s of thousands of lines of code. It's obscene. And some things happen to be getting rendered with XTemplates and I'll find pieces like

values.ApplicantLastName or
values.EndDate but I don't know what else values has inside it because I didn't write the code and am coming upon its use after the fact.

So I was wondering if anyone had any sneaky tricks on uncovering what the values object contained.

willigogs
21 Aug 2013, 6:13 AM
Ah ok.

Have you tried using Firebug and performing and simple "console.log(values)"?

You should then be able to see what is contained within this variable.

jbeaven
21 Aug 2013, 6:14 AM
Yeah when I do that it says "[object Object]" which is completely helpful the way Firebug can be so literal sometimes.

willigogs
21 Aug 2013, 6:17 AM
Really? That isn't the case when I've tried it... :\

I'll go have a test with some of my own code and see if I can spot anything.

In the meantime, if you haven't already done so, I would strongly recommend installing "Illuminations", which adds a further tab inside Firebug. This is invaluable when coding with EXTJS, as it gives visibility into all of your EXT objects.

http://www.illuminations-for-developers.com/

jbeaven
21 Aug 2013, 6:19 AM
Thanks for the heads up.

I'll try it out.

willigogs
21 Aug 2013, 6:34 AM
Ok, it turns out console.logging isn't quite as easy inside an XTemplate as I'd imagined...

I'm sure there must be an easier way, but one way I achieved this was by calling a function within the XTemplate itself, as below:


var template = new Ext.XTemplate(
'<tpl if="this.consolelog(values)"></tpl>',
'<tpl for=".">',
/*
Your template logic goes here
*/
'</tpl>', {
consolelog: function(values) {
console.log(values)
}
});


This then splutted out the entire recordset as an array of objects which I could drill into using firebug.

jbeaven
21 Aug 2013, 6:36 AM
Hmmm...I would never have thought to create a function like that for this purpose but yeah that seems like the logical thing to do.

Thanks for that tip. I'm seeing what I need now.

willigogs
21 Aug 2013, 6:38 AM
Hmmm...I would never have thought to create a function like that for this purpose but yeah that seems like the logical thing to do.

Thanks for that tip. I'm seeing what I need now.
I agree - it isn't what I would've naturally thought to do either :D

I usually use this type of logic when I need to run the values through a function before displaying in the template, so was a quick and dirty way to get the values out.

You can simply add this function when debugging, then remove again.

Hope it helped :)