我认为这有一个简单的解决方案。
我有一个列表,我想将其制作成 ListView 。东西是动态添加的。
HTML:
<div data-role="content" data-theme="b" class="content-primary">
<div id="friends_list_view" class="content-primary" data-theme="c">
<ul data-role="listview" data-filter="true" data-theme="c">
</ul>
</div>
</div>
jQuery:
for(i in names){
listString = '<li><a href="#">'+i+'</a></li>';
$("#friends_list_view ul").append(listString);
}
$("#friends_list_view ul").listview('refresh');
$.mobile.hidePageLoadingMsg();
$.mobile.changePage( "#friends", { transition: "slide"} );
我得到:
Uncaught cannot call methods on listview prior to initialization; attempted to call method 'refresh'
当我将其更改为 $("#friends_list_view ul").listview();
我得到:
Uncaught TypeError: Cannot read property 'jQuery16409763167318888009' of undefined
最佳答案
带有 ListView 的页面可能未初始化。尝试先调用它:
$('#pageWithListview').page();
关于jQuery Mobile ListView : initialize error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9637095/