I’m experimenting with a jQuery Mobile app that will eventually end up as a non-Web app on a mobile device and so all the content has to be local. For that reason (I think) I need to construct the app in a single page delineated by data-role="page" tags otherwise the ajax loading mechanism in jQuery Mobile doesn’t seem to work.
The app will read data from a local storage DB and display it on the page in an unordered list, styled using jQuery Mobile to look like a native app.
In my $(document).ready() function I execute the DB lookup and for each results, I create an <li> tag around my DB results and then call $(".list").append(li_str); where .list is the class of my <ul> tag.
The page renders as if jQuery Mobile isn’t present – I see the correct data in each <li> but it doesn’t look correct.
Comparing this result with a version where I hard code the <li> tags in the page HTML – it looks like jQuery Mobile modifies the tags and inserts a lot of new classes etc.
Maybe I need to build the page from the DB earlier in the page load cycle? Any suggestions?
The problem is this issue. So, change your code:
Alternately, you can delay creating the list view until all of the elements have been created (as described in the linked thread):
Sorry for code dumps; I couldn’t get this working in jsfiddle.