I'd like to generate a listview dynamically with jquery mobile. I have this code but the .listview('refresh') is not working:
<div id="content" data-role="content">
</div><!-- /content -->
<script type="text/javascript">
$.ajax({
type: "GET",
url: "my.json",
dataType: "json",
success: function(articles) {
var html = '<ul id="hellolist" data-role="listview"><li><h3>One</h3></li><li><h3>Two</h3></li><li><h3>Three</h3></li></ul>';
$('#content').append($(html));
$('#hellolist').listview('refresh');
}
});
</script>
If I generate only the list items or I don't use ajax the refresh formats the listview well.
test #1: it works well.
<div id="content" data-role="content">
<ul id="hellolist" data-role="listview"> </ul>
</div><!-- /content -->
<script type="text/javascript">
var html = '<li><h3>One</h3></li><li><h3>Two</h3></li><li><h3>Three</h3></li>';
$('#hellolist').append($(html));
$('#hellolist').listview('refresh');
</script>
test #2: it works well.
<div id="content" data-role="content">
</div><!-- /content -->
<script type="text/javascript">
var html = '<ul id="hellolist" data-role="listview"><li><h3>One</h3></li><li><h3>Two</h3></li><li><h3>Three</h3></li></ul>';
$('#content').append($(html));
$('#hellolist').listview('refresh');
</script>
test #3: it works well.
<div id="content" data-role="content">
<ul id="hellolist" data-role="listview"> </ul>
</div><!-- /content -->
<script type="text/javascript">
$.ajax({
type: "GET",
url: "my.json",
dataType: "json",
success: function(articles) {
var html = '<li><h3>One</h3></li><li><h3>Two</h3></li><li><h3>Three</h3></li>';
$('#hellolist').append($(html));
$('#hellolist').listview('refresh');
}
});
</script>
Anybody has any idea to solve this issue?