use*_*333 4 html jquery jquery-mobile jquery-mobile-listview
我有一个来自ajax的数组,我需要创建jQuery Mobile Listview.我没有找到这方法,所以有可能吗?
这是一个有效的例子:http://jsfiddle.net/Gajotres/SS7vJ/
另一个数组示例:http://jsfiddle.net/Gajotres/yHHWQ/
$(document).on('pagebeforeshow', '#index', function(){
$('<ul>').attr({'id':'test-listview','data-role':'listview', 'data-filter':'true','data-filter-placeholder':'Search...'}).appendTo('#index [data-role="content"]');
$('<li>').append('<a href="#">Audi</a>').appendTo('#test-listview');
$('<li>').append('<a href="#">Mercedes</a>').appendTo('#test-listview');
$('<li>').append('<a href="#">Opel</a>').appendTo('#test-listview');
$('#test-listview').listview().listview('refresh');
});
Run Code Online (Sandbox Code Playgroud)
另外不要忘记调用.listview(两次,第一次没有刷新参数,第二次使用刷新参数.没有它你会收到这个错误:
在初始化之前无法调用listview上的方法
如果你想了解更多关于jQuery mobile如何处理动态添加的内容及其标记,请看一下这篇文章,要透明它是我的个人博客,或者在这里找到它.