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 refresh method.
Is there a way to check if the component has initialized or not?
This is the error I get:
cannot call methods on listview prior to initialization
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
Try
$list.listview();
$list.listview('refresh');
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