在我的列表视图中,我有几个问题列表,现在我尝试在单击刷新按钮时进行操作,列表视图中的问题将按随机顺序刷新。我想知道我是否可以只刷新页面的列表部分而不是整个页面?
<ul id="list" data-role="listview" data-filter="true" data-filter-reveal="true" data-filter-placeholder="Search Questions..." data-inset="true" ></ul>
<script>
var jsonfile = 'data.json';
var qData = [];
var qHint = [];
$.getJSON(jsonfile, function(data) {
while (data.activity.length) {
var index = Math.floor(Math.random() * data.activity.length);
qData.push(data.activity[index].question);
qHint.push(data.activity[index].hint);
data.activity.splice(index, 1)
}
for (var i = 0; i < 8; i++) {
question(qData[i], i);
hint(qHint[i], i);
$('#text' + (i + 1)).textinput();
$('#submit' + (i + 1)).button();
$('#cancel' + (i + 1)).button();
}
function question(data, i) {
$('#list').append('<li><a href=#mypanel'+ (i + 1)+ ' data-icon="arrow-l" data-iconpos="notext" data-shadow="false" data-iconshadow="false" class="ui-icon-nodisc" id="list">'+ data + '</a></li>'); // list item
}
function hint(data, i)
{
$('#mypanel' + (i + 1)).append("<div align='center' style='margin-top:30px;'><font style='font-family:Helvetica, Arial, sans-serif ;color:white;' size='5px' ><b>Question Hint : </b></font></div><br/><label for=text" + (i + 1) + " id=paneltitle"+ (i + 1)+ " style='margin-top:10px;text-align:center;color:white;'>"+ data + "</label>");// panel item
$('#paneltitle' + (i + 1)).append('<input type="text" id=text'+ (i + 1) + ' >');
$('#mypanel' + (i + 1)).append('<a href="#header" data-role="button" id=submit'+ (i + 1)+ ' data-inline="true" data-rel="close" data-icon="check" style="margin-left:75px;">Submit</a>');
$('#mypanel' + (i + 1)).append('<a href=#mypanel'+ (i + 1)+ ' data-role="button" id=cancel'+ (i + 1)+ ' data-inline="true" data-rel="close" data-icon="delete2" style="margin-left:75px;">Cancel</a>');
}
//Affected part
$('#PageRefresh').click(function() {
location.reload();
});
$('#list').listview('refresh');
})
<div data-theme="a" data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a id="PageRefresh" data-icon="refresh">Refresh</a></li>
</ul>
</div>
</div>