我在這裏創建了一個代碼,通過按下按鈕將數組內容存儲到列表視圖中,我的問題是listview內容會堆疊。我想每次按下按鈕清除以前的列表視圖內容,並能夠再次顯示更新的存儲陣列內容。清除列表視圖的內容
<div id="MainPage" data-role="page" >
<div data-role="content">
<a href="#ViewPage" data-role="button" onClick="displayArray()">RENAME</a>
</div>
</div>
<div id="ViewPage" data-role="page" >
<div data-role="header" data-position="fixed">
<a href="#MainPage" data-role="button" data-icon="back">BACK</a>
<h1>View Page</h1>
</div>
<div data-role="content">
<ul id="viewlist" data-role="listview" data-filter="true" data-filter-placeholder="Sample Contents" data-inset="true">
<!-- array contents goes here -->
</ul>
</div>
</div>
<script>
var sampleContent = new Array();
displayArray()
{
//i want to place a code here that would clear the listview contents
for(var scan=0; scan<sampleContent.length; detect++)
{
//looping of the array contents into the listview
$('#viewlist').append('<li><a href="#">' + sampleContent[scan] + '</a></li>').listview("refresh");
}
}
</script>
我被這個問題困住了,任何幫助或建議將很樂意接受預先感謝。
可以顯示你的'sampleContent()'函數 –
sampleContent是我用來存儲數據到列表視圖的數組。我想在for循環之前清除displayArray()函數中的listview。我試過('#viewlist')。empty();但之後不再添加listview內容。 –