-
6 Nov 2011 8:52 PM #1
Answered: Override Ext.List to use UL/LI instead of Divs
Answered: Override Ext.List to use UL/LI instead of Divs
Im just wondering how to customize the the xtype:list , so that the markup creates a UL and the itemTpl creates LI's, instead of Divs.
I'm sure there is a way but i'm pretty new to sencha.
Thanks!
-
Best Answer Posted by 29er
I just decided to make a custom component instead of forcing a List or DataView. damn, who would have thought it would be such work to make a simple UL control with an xtemplate for the li items!
Thanks
-
7 Nov 2011 8:40 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,169
- Vote Rating
- 28
- Answers
- 83
I looked into this quickly, and it seems that if you specified an xtemplate like:
it should work as you would like. Try setting this in the config object that you pass to the constructor.Code:itemTpl : Ext.create('Ext.XTemplate', '<ul>', '<tpl for=".">', '<li>', '{my_tokens_here}', '</li>', '</tpl>', '</ul>' ),
Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
7 Nov 2011 12:42 PM #3
Thanks Jay, but it doesn't emit the html like i need.
it still gives me markup like below:
here is my itemTpl:
Here are two items in the list, still wrapping with div's for each item in the listHTML Code:var mytpl = new Ext.XTemplate('<ul><tpl for=".">', '<li><a href="{a_href}">', '<img alt="{desc_text}" width="72" src="{img_url}"/>', '<span>{desc_text}</span>', '</a></li>', '</tpl></ul>');
when what i really want is something like this:Code:<div class="x-list-item" itemindex="0" id="ext-element-16"> <div class="x-list-item-label"> <ul> <li><a href="test"><img alt="test" width="72" src="on.png"/> <span>Description</span></a></li> </ul> </div> </div> <div class="x-list-item x-item-selected" itemindex="1" id="ext-element-17"> <div class="x-list-item-label"> <ul> <li><a href="mynewhref"><img alt="Descript2" width="72" src="off.png" /><span>Descript2</span></a></li> </ul> </div> </div>
maybe i need to use something like autoEl ? or just create a custom component and bypass Ext.List altogether ?Code:<ul id="grid"> <li> <a href="myhref"><img src="icon.png" alt="Description" width="72" /> <span>Description</span> </a></li> <li> <a href="myhref"><img src="con2.png" alt="Descript2" width="72" /> <span>Description2</span> </a></li>... ....more LI's here </ul>
Thanks for the help.
-
8 Nov 2011 7:58 PM #4
I just decided to make a custom component instead of forcing a List or DataView. damn, who would have thought it would be such work to make a simple UL control with an xtemplate for the li items!
Thanks
-
9 Nov 2011 6:57 PM #5
May I ask why? I mean if you are using Touch your probably not using it because of it's semantics… just saying. Turning a few divisions into proper list items is very minute in comparison to all the other none semantic decisions that exist. There really isn't much to gain, but increasing code complexity with this… That said I agree that list items should actually be list items but surely those decisions were made for a decent reason, which I can live with.
-
10 Nov 2011 8:39 AM #6
yes you have a good point, I can write CSS to make the list look however i want. It's just that i am very accustomed to using UL's (with no decoration) to format/style 'groups' of items in any manner imaginable. but you're right, I have found that the custom control I built is very buggy in mobile applications, and I decided to use the default Ext.List and style the div's instead.
I know there must be a reason for using divs instead of UL/OL's, but sometimes i wonder just what that is


Reply With Quote