PDA

View Full Version : [CLOSED] [ST2.1] parent is array in nested XTemplate



vvs
9 Nov 2012, 4:20 AM
ST version tested:

Ext 2.1
Description:

in nested XTemplate parent returns array instead of object
Test Case:



var tpl1 = new Ext.XTemplate(
'<tpl for=".">',
'a: {a}',
'<tpl for="b">',
'{% console.log(parent) %}',
'</tpl>',
'</tpl>'
),


tpl2 = new Ext.XTemplate(
'a: {a}',
'<tpl for="b">',
'{% console.log(parent) %}',
'</tpl>'
),
obj = { 'a': 'a', 'b': [{ 'c': 'c'}] };


tpl1.apply(obj);
tpl2.apply(obj);


The result that was expected:

In both bases object should be logged to console.

The result that occurs instead:

tpl1 - array is printed instead.

[Object]

0: Object

a: "a"
b: Array[1]
__proto__: Object
length: 1

__proto__: Array[0]

‚Äč
tpl2 - result is correct.

Object {a: "a", b: Array[1]}

a: "a"
b: Array[1]
__proto__: Object

mitchellsimoens
9 Nov 2012, 4:57 AM
new Ext.XTemplate(
'<tpl for=".">',
'a: {a}',
'<tpl for="b">',
'{% console.log(parent) %}',
'</tpl>',
'</tpl>'
)

Is not valid for your object like:


{
a : 'a',
b : [
{
c : 'c'
}
]
}

The reason is <tpl for=".">...</tpl> is told to iterate through an array but you are feeding it an object.