PDA

View Full Version : Array access inside a template?



whirling dervish
1 Jun 2012, 7:58 AM
Is there anyway to get access to an array inside a template?

So if I have values.array and want to get to the first place for instance, how would I do values.array[0] in a template?

whirling dervish
5 Jun 2012, 5:12 AM
Anyone know how to do this? Can it be done?

redraid
5 Jun 2012, 6:11 AM
Ext.onReady(function () {
var data = {
name: 'N1',
phones: [
'P1',
'P2'
],
objs: [
{
name: 'K1'
},
{
name: 'K2'
}
]
};

var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<p>Name: {name}</p>',
'<p>1st phone: {[values.phones[0]]}</p>',
'<p>2nd obj name: {[values.objs[1].name]}</p>',
'</tpl>'
);

window.document.write(tpl.apply(data));
});

whirling dervish
5 Jun 2012, 7:22 AM
Hmm, I could have sworn I tried that syntax last week and it didn't work. Worked for me now, thanks.