{"id":539,"date":"2011-07-12T11:36:45","date_gmt":"2011-07-12T08:36:45","guid":{"rendered":"https:\/\/polyetilen.lt\/?p=539"},"modified":"2023-05-02T11:09:18","modified_gmt":"2023-05-02T08:09:18","slug":"jquery-mobile-listview-error-calling-method-refresh","status":"publish","type":"post","link":"https:\/\/polyetilen.lt\/en\/jquery-mobile-listview-error-calling-method-refresh","title":{"rendered":"JQuery Mobile listview error calling method refresh"},"content":{"rendered":"<p>Made two pages on JQuery Mobile library, put on every page listview. Lists are dynamically generated. But notice if I call the refresh on the invisible list, an error is returned: Uncaught cannot call methods on listview prior to initialization; attempted to call method 'refresh'<\/p>\n<p>A simple solution to update the list is to check with the selector :visible if the listview item is visible. In the example, two dynamic list, on the various pages are updated when the page displayed.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt; \r\n&lt;html&gt; \r\n&lt;head&gt;\r\n    &lt;meta charset=&quot;utf-8&quot;&gt;\r\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, minimum-scale=1, maximum-scale=1&quot;&gt;\r\n    &lt;title&gt;ListView Test&lt;\/title&gt;\r\n    \r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;..\/css\/jquery.mobile-1.0b1.css&quot; \/&gt;\r\n    \r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;..\/js\/jquery-1.6.1.min.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;..\/js\/jquery.mobile-1.0b1.min.js&quot;&gt;&lt;\/script&gt;\r\n    \r\n    &lt;script type=&quot;text\/javascript&quot;&gt;\r\n\t\tvar list1 = list2 = '';\r\n\t\tfor(i=0;i&lt;5;i++){\r\n\t\t\tlist1 += '&lt;li&gt;&lt;a href=&quot;#list&quot; data-icon=&quot;arrow-r&quot;&gt;item'+i+'&lt;\/a&gt;&lt;\/li&gt;';\r\n\t\t\tlist2 += '&lt;li&gt;&lt;a href=&quot;#index&quot; data-icon=&quot;arrow-r&quot;&gt;item'+i+'&lt;\/a&gt;&lt;\/li&gt;';\r\n\t\t}\r\n\t\t\r\n\t\t$(document).bind(&quot;pageshow&quot;, function(){\r\n\t\t\tif($(&quot;#list1:visible&quot;).length){\r\n\t\t\t\t$('#list1').html(list1);\r\n\t\t\t\t$('#list1').listview('refresh');\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\tif($(&quot;#list2:visible&quot;).length){\r\n\t\t\t\t$('#list2').html(list2);\r\n\t\t\t\t$('#list2').listview('refresh');\r\n\t\t\t}\r\n\t\t});\r\n    &lt;\/script&gt;\r\n\r\n&lt;\/head&gt; \r\n&lt;body&gt; \r\n\r\n&lt;div data-role=&quot;page&quot; id=&quot;index&quot;&gt;\r\n\t&lt;div data-role=&quot;content&quot;&gt;\r\n\t\t&lt;ul data-role=&quot;listview&quot; id=&quot;list1&quot;&gt;\r\n        &lt;\/ul&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;div data-role=&quot;page&quot; id=&quot;list&quot;&gt;\r\n\t&lt;div data-role=&quot;content&quot;&gt;\r\n\t\t&lt;ul data-role=&quot;listview&quot; id=&quot;list2&quot;&gt;\r\n        &lt;\/ul&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Or attach a handler of list refresh to the page show event.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt; \r\n&lt;html&gt; \r\n&lt;head&gt;\r\n    &lt;meta charset=&quot;utf-8&quot;&gt;\r\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, minimum-scale=1, maximum-scale=1&quot;&gt;\r\n    &lt;title&gt;ListView Test&lt;\/title&gt;\r\n    \r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;..\/css\/jquery.mobile-1.0b1.css&quot; \/&gt;\r\n    \r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;..\/js\/jquery-1.6.1.min.js&quot;&gt;&lt;\/script&gt;\r\n    &lt;script type=&quot;text\/javascript&quot; src=&quot;..\/js\/jquery.mobile-1.0b1.min.js&quot;&gt;&lt;\/script&gt;\r\n    \r\n    &lt;script type=&quot;text\/javascript&quot;&gt;\r\n\t\tvar list1 = list2 = '';\r\n\t\tfor(i=0;i&lt;5;i++){\r\n\t\t\tlist1 += '&lt;li&gt;&lt;a href=&quot;#list&quot; data-icon=&quot;arrow-r&quot;&gt;item'+i+'&lt;\/a&gt;&lt;\/li&gt;';\r\n\t\t\tlist2 += '&lt;li&gt;&lt;a href=&quot;#index&quot; data-icon=&quot;arrow-r&quot;&gt;item'+i+'&lt;\/a&gt;&lt;\/li&gt;';\r\n\t\t}\r\n\t\t\r\n\t\t$(document).ready(function(){\r\n\t\t\t$('#index').live('pageshow',function(event){\r\n\t\t\t\t$('#list1').html(list1);\r\n\t\t\t\t$('#list1').listview('refresh');\r\n\t\t\t});\r\n\t\t\t\r\n\t\t\t$('#list').live('pageshow',function(event){\r\n\t\t\t\t$('#list2').html(list2);\r\n\t\t\t\t$('#list2').listview('refresh');\r\n\t\t\t});\r\n\t\t});\r\n\t\t\r\n    &lt;\/script&gt;\r\n\r\n&lt;\/head&gt; \r\n&lt;body&gt; \r\n\r\n&lt;div data-role=&quot;page&quot; id=&quot;index&quot;&gt;\r\n\t&lt;div data-role=&quot;content&quot;&gt;\r\n\t\t&lt;ul data-role=&quot;listview&quot; id=&quot;list1&quot;&gt;\r\n        &lt;\/ul&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;div data-role=&quot;page&quot; id=&quot;list&quot;&gt;\r\n\t&lt;div data-role=&quot;content&quot;&gt;\r\n\t\t&lt;ul data-role=&quot;listview&quot; id=&quot;list2&quot;&gt;\r\n        &lt;\/ul&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;\/html&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Made two pages on JQuery Mobile library, put on every page listview. Lists are dynamically generated. But notice if I call the refresh on the invisible list, an error is returned: Uncaught cannot call methods &hellip; <a href=\"https:\/\/polyetilen.lt\/en\/jquery-mobile-listview-error-calling-method-refresh\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"http:\/\/polyetilen.lt\/?p=205","footnotes":""},"categories":[8],"tags":[167,67,69],"class_list":["post-539","post","type-post","status-publish","format-standard","hentry","category-programavimas","tag-atnaujinimas","tag-jquery-mobile","tag-listview","en-US"],"_links":{"self":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts\/539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/comments?post=539"}],"version-history":[{"count":2,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"predecessor-version":[{"id":543,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/posts\/539\/revisions\/543"}],"wp:attachment":[{"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/polyetilen.lt\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}