PDA

View Full Version : How to use a template to only show items loaded in store?



d007
17 Sep 2011, 7:03 AM
If I have an array of unknown data, how can I tell extjs to loop through the data and generate a template based on what is inside the data.
So I have an array with values item1, item2, item3,..., item 50
My current template does an if statement for every single possible item like this:


'<tpl for=".">',

'<tpl if="item1">',
'<span>{item1}</span>',
'</tpl>',
'<tpl if="item2">',
'<span>{item2}</span>',
'</tpl>',
etc
Which I am thinking is very inefficient as I have a lot of items to check for. Whereas if I could loop through 'array' which has only the items that were sent to the store from the server it would be better.
How can I accomplish this? Thanks

bharatn
19 Sep 2011, 10:49 PM
Why dont you use generic field 'item'.




<span>{item}</span>',

d007
20 Sep 2011, 12:58 AM
I don't understand how that is going to work. The model names are item1, item2 etc. I can't send all the different pieces of potential item data to a single data model field called item.