I\'ve coded my way into a corner.
I need to call listview(\"refresh\")
on a list, however it may not have been initialized at the point I am calling the
Try
$list.listview();
$list.listview('refresh');
you can simply create a global variable
var is_mobile_init = false;
at the top of your scripts. then set it to true after you include jquery mobile.
then before refreshing write,
if (is_mobile_init)
$myUL.listview('refresh');
this way, you don't need to keep track of all the various classes and it is intuitive
When a listview
widget is initialized, it's given the ui-listview
class, so we can test for this class to see if it has been initialized:
//select the listview
var $myUL = $('#my-ul-element');
//add a list-item to the listview
$myUL.append('<li>I\'m New!</li>');
//check if the listview has the ui-listview class
if ($myUL.hasClass('ui-listview')) {
//this listview has already been initialized, so refresh it
$myUL.listview('refresh');
} else {
//this listview has not yet been initialized, so it gets initialized
$myUL.listview();//or you can use .trigger('create');
}
This should help alleviate the error you're getting.
Also, the .hasClass('[class]')
function returns true
/false
if the element has the [class]
: http://api.jquery.com/hasClass
For me the solution to this message was to add data-role="listview"
to my ul
element. I could then use the method .listview('refresh')
in my event handlers.