PDA

View Full Version : Templates and <li> elements



pex
27 Sep 2007, 1:50 AM
Hello!

I would like to generate a <ul> with <li> items based on JSON data. For this I thought templates to be a good candidate. The JSON data I have is in the form:


{"rows":[{"tag_id":"22","name":"GA4 Visitor"},{"tag_id":"5","name":"GLIK Mailing"},{"tag_id":"56","name":"testee"},{"tag_id":"60","name":"test777"}]}

The HTML should be like:


<ul>
<li id="22">GA4 Visitor</li>
<li id="5">GLIK Mailing</li>
...
</ul>

So I created a template as follows:


this.tagListTemplate = new Ext.Template([
'<li id={id}>{tag_name}</li>'
]);
this.tagListTemplate.compile();


My question now is, how do I populate the template with the JSON data?

fay
27 Sep 2007, 2:18 AM
There's loads of info on the site for this:

Examples:



feed-viewer.js
chooser.js


See:



http://extjs.com/forum/showthread.php?p=66213#post66213
http://www.jackslocum.com/blog/2006/10/06/domhelper-create-elements-using-dom-html-fragments-or-templates/


Search:



template json
template jsonview