jQuery Mobile List View:初始化错误

Jos*_*hDG 4 html jquery listview jquery-mobile

我认为这有一个简单的解决方案.

我有一个列表,我想进入列表视图.东西是动态添加的.

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>
Run Code Online (Sandbox Code Playgroud)

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"} );
Run Code Online (Sandbox Code Playgroud)

我明白了:

在初始化之前,Uncaught无法在listview上调用方法; 试图调用方法'刷新'

当我改变它只是$("#friends_list_view ul").listview();我得到:

未捕获的TypeError:无法读取未定义的属性'jQuery16409763167318888009'

小智 6

列表视图的页面可能未初始化.尝试先调用它:

$('#pageWithListview').page();
Run Code Online (Sandbox Code Playgroud)