I’m trying to dynamically create a navbar from data i fetch from a web api serving json data. Here’s the code: https://gist.github.com/2962277
If i use:
<div data-role="navbar">
<ul>
<li><a href="a.html">One</a></li>
<li><a href="b.html">Two</a></li>
</ul>
</div>
directly in html code works fine, but this is not what im looking for. I want to be able to create the list elements from the data in the like the code in gist show. Anyone could point me in the right direction?
Once you have concocted your HTML for the navbar widget, you simply call
.trigger('create')on the widget:Here is a demo: http://jsfiddle.net/Jde95/
This will trigger jQuery Mobile to initialize the widget.
For Example:
Notice how I concocted the HTML, and used the
.append()function.