[英]Dynamically add content to a listview jquery mobile
i am trying to dynamically load items into a listview using javascript. 我正在尝试使用javascript将项目动态加载到listview中。
below is my javascript code 以下是我的JavaScript代码
//Dynamically load data fields for items
function initialiseFields(listViewId){
for(var i = 0; i < 10; i++){
loadField(listViewId, "hello", "type", "value goes here");
}
}
/**
load single item field
**/
function loadField(listView, label, type, value){
//append the list
$('#listView').append("<li><h3>"+label+":</h3><h4>"+value+"</h4></li>");
$('#listView').listview('refresh');
}
Html5 code HTML5代码
<body onLoad="initialiseFields('itemFieldslist');">
<div data-role="page" id="page">
<div data-role="header" data-position="fixed" data-theme="b" >
<a href="newClaim.html">Back</a>
<h1><span style="margin-left:1em">List</span></h1>
</div>
<div data-role="content">
<ul data-role="listview" id="itemFieldslist" data-inset="true" data-scroll="true" >
<li data-role="list-divider"> <h2>Title</h2></li>
</ul>
</div>
</div>
</body>
The contents of the listview is always empty except for displaying the header divider for the list 除了显示列表的标题分隔符之外,listview的内容始终为空
Can you try to wrap initialiseFields
in: 您可以尝试将
initialiseFields
包装为:
$(document).bind('pageinit')
if you check the jquery mobile docs you can see that they discourage the use of $(document).ready()
如果您查看jquery移动文档,您会发现它们不鼓励使用
$(document).ready()
check here: jquery events 检查这里: jQuery事件
I'll check myself later. 我待会再检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.