This concerns jQuery Mobile 1.0 Beta 1
I love jQuery Mobile but for the love of god I can't figure out how to dynamically add list items. I first tried without binding the pagebeforecreate event -- the items were appended to DOM but were not visible, even tho I tried calling many combinations of the following:
$("#categories").listview();
$("#categories").listview('refresh');
$("#categories").listview('refresh', true);
I was getting "Result of expression 'b[0]' [undefined] is not an object." error.
I then figured that I could bind to pagebeforecreate event to append the li-items before jQuery Mobile does its magic. However, this doesn't help.. same result as before.
$().ready(function() {
$("#browse-categories").live('pagebeforecreate', function() {
$.get('http://foo.com/api/categories.xml', function(data) {
$xml = $(data);
$xml.find('entry').each(function() {
$("#categories").append("<li>" + $(this).find('title').text() + "</li>")
});
});
});
});
The HTML:
<div data-role="page" id="browse-categories">
<div data-role="header">
<h1>Categories</h1>
</div>
<div data-role="content">
<ul data-role="listview" id="categories">
</ul>
</div>
<div data-role="footer">
<h4>Page Footer</h4>
</div>
</div>
So what the heck?