我想用jquery mobile動態生成listview。我有這樣的代碼,但.listview(「刷新」)不工作:從ajax動態生成列表視圖 - 刷新不工作
<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>
如果我只生成列表中的項目或我不使用AJAX刷新格式列表視圖很好。
測試#1:效果很好。
<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>
測試2:效果很好。
<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>
測試#3:效果很好。
<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>
有人有什麼想法來解決這個問題嗎?
謝謝,這是解決方案:$('#hellolist')。listview(); – matyig