jQuery 如何动态构建列表视图 JQueryMobile
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8753783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to dynamically build list view JQueryMobile
提问by shyamshyre
I need to dynamically add a list view. I am able to build the list view dynamically but i am appending
我需要动态添加一个列表视图。我能够动态构建列表视图,但我正在附加
The HTML code snippet.
<ul id="mymenu" data-role="listview" >
</ul>
Jquery Code Snippet.
$("#accpmenu").append('<li><a href='+ "#" + ' id="a" "> <img src="letterheader.png" >'+ this.textContent + ' </a> </li>');
I even want to dynamically build the and then append
The HTML code snippet.
<ul id="mymenu" data-role="listview" >
</ul>
Jquery Code Snippet.
$("#accpmenu").append('<li><a href='+ "#" + ' id="a" "> <img src="letterheader.png" >'+ this.textContent + ' </a> </li>');
我什至想动态构建然后附加
Thanks Shyam
谢谢 夏姆
回答by mram888
After appending you must refresh the list:
附加后,您必须刷新列表:
$("#mymenu").listview("refresh");
回答by user700284
Here is an example which creates a list dynamically.
这是一个动态创建列表的示例。
Let me know if that helps.
如果这有帮助,请告诉我。
回答by Arun
I have use below code working fine to me
我使用下面的代码对我来说工作正常
Dynamic Listview
动态列表视图
<script>
var myArray = ["Arun", "kumar", "Mani", "Vimal", "Vinoth"];
$.each(myArray, function(index, value){
console.log("INDEX: " + index + " VALUE: " + value);
});
var output = [];
for (var i = 0; i <myArray.length; i++) {
output.push('<li><img src="img/img_help.png">' + myArray[i] +'</li>');
}
$('#coursemates').append(output.join('')).listview('refresh');
$("#coursemates").listview("refresh");
</script>