I am using jQuery Mobile for my PhoneGap app in Xcode. I have created multiple pages having tabs in footer. It works properly in static page as follows.
<div data-role="footer" data-position="fixed">
<div data-id="mainTab" data-role="navbar">
<ul id="footer_tabs">
<li><a href="search_page.html" data-transition="slideup" data-icon="search">Search</a></li>
<li><a href="my_favorite_page.html" data-icon="star" data-transition="slideup">Favorites</a></li>
<li><a href="my_account_page.html" data-icon="gear" data-transition="slideup">Account</a></li>
<li><a href="create_ad_page.html" class="ui-state-persist ui-btn-active" data-transition="slideup" data-icon="plus">Create Ad</a></li>
</ul>
</div>
<div>
When I tried to load tabs according to user role. HTML code in page :
<div data-role="footer" data-position="fixed">
<div data-id="mainTab" data-role="navbar">
<ul id="footer_tabs">
</ul>
</div>
<div>
jQuery code:
$('#footer_tabs').append('<li><a href="search_page.html" data-transition="slideup" data-icon="search">Search</a></li>');
$('#footer_tabs').append('<li><a href="my_favorite_page.html" data-transition="slideup" data-icon="search">Favorite</a></li>');
$('#footer_tabs').append('<li><a href="my_account_page.html" data-transition="slideup" data-icon="search">Account</a></li>');
if(userRole == '3'){
$('#footer_tabs').append('<li><a href="create_ad_page.html" data-transition="slideup" data-icon="search">Create Ad</a></li>');
}
$('#footer-tabs').listview('refresh');
Picture of static loading:
Picture loading from jQuery:
I have refreshed the list too, but not working. I don't know what the problem is. Please help me.
Thanks, -regeint
I'm not sure how you refresh
a nabvar
widget in the jQuery Mobile framework but I know that you can remove the previous navbar
and insert a fresh one:
//create an output variable, I used an array
var output = ['<div data-id="mainTab" data-role="navbar"><ul id="footer_tabs">'];
//push items onto the output array
output.push('<li><a href="search_page.html" data-transition="slideup" data-icon="search">Search</a></li>');
output.push('<li><a href="my_favorite_page.html" data-transition="slideup" data-icon="search">Favorite</a></li>');
output.push('<li><a href="my_account_page.html" data-transition="slideup" data-icon="search">Account</a></li>');
if(userRole == '3'){
output.push('<li><a href="create_ad_page.html" data-transition="slideup" data-icon="search">Create Ad</a></li>');
}
output.push('</ul></div>');
//this last line is important, the output array is being joined into a string, then appended to the footer element,
//also the `create` event is being triggered on the footer element so the jQuery Mobile framework will update the widget with all the necessary styles
$('[data-role="footer"]').html(output.join('')).trigger('create');
Here is a demo: http://jsfiddle.net/ZVGSZ/
Notice that I created an array of HTML strings and then join
ed them together to do a single .append()
rather than an append for each HTML string (.html(string) == (.remove() + .append(string))
).
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