first, sorry if my english bad,....
in my script, variable tplData below is dynamic,... (lets say it generates from database)
so, every chid, can have another child. and so on,....
now, i'm stack how to iteration it,..
var tplData = [{
name : 'Naomi White'
},{
name : 'Yoko Ono'
},{
name : 'John Smith',
child : [{
name:'Michael (John\'s son)',
child: [{
name : 'Brad (Michael\'s son,John\'s grand son)'
},{
name : 'Brid (Michael\'s son,John\'s grand son)',
child: [{
name:'Buddy (Brid\'s son,Michael\'s grand son)'
}]
},{
name : 'Brud (Michael\'s son,John\'s grand son)'
}]
}]
}];
var myTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div style="background-color: {color}; margin: 10px;">',
'<b> Name :</b> {name}<br />',
// how to make this over and over every child (while it has )
'<tpl if="typeof child !=\'undefined\'">',
'<b> Child : </b>',
'<tpl for="child">',
'{name} <br />',
'</tpl>',
'</tpl>',
///////////////////////////////////////
'</div>',
'</tpl>'
);
myTpl.compile();
myTpl.overwrite(document.body, tplData);
Something like this:
var myTpl = new Ext.XTemplate(
'<tpl for=".">',
'<div style="background-color: {color}; margin: 10px;">',
'<b> Name :</b> {name}<br />',
'<tpl if="typeof child !=\'undefined\'">',
'<b> Child : </b>',
'{[ this.recurse(values) ]}',
'</tpl>',
'</tpl>',
'</div>',
'</tpl>',
{
recurse: function(values) {
return this.apply(values.child);
}
}
);
Untested since Ext Core doesn't include XTemplate and that is what can be included in jsbin and jsfiddle
I'm sure the output is nowhere near what you need, but it shows how to recurse. You may need to break your template into two to get the output you are going for. Check out this slide show for more: http://www.slideshare.net/senchainc/advanced-templates-5971877
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With