当我调用 ajax 到我的服务器时,我得到了 1000 个数据,我将这些数据存储在我的本地存储中并在 jQuery 移动列表视图中显示它,但这需要将近 50-60 秒来显示或加载数据。如何使这个过程快速?
这是我的代码:
var PollChallengeVoterDataUrl = ROOT+'testmaster/view/'+intCLMid+'/'+intCLTid+'/?UserId='+intUserId+'&UserRole='+intUserRole;
var data = "CampaignId="+IntCampaignId;
jQuery.ajax({
url: PollChallengeVoterDataUrl,
type: "GET",
async: false,
dataType: 'jsonp',
jsonpCallback: 'Cconnect',
data: data,
success: function(response,request)
{
var statusresult=response.success;
if(statusresult)
{
var data_arr = response.pollChallengeDetail[0];
var data_len = response.pollChallengeDetail[0]['pollChallengeCount'];
localStorage.removeItem(PollChallengeVoterList);
if(data_len > 0)
{
$.each(data_arr, function(k, v) {
if(k == 0)
{
}
addToStorage(k,v,PollChallengeVoterList);
});
}
}
},
error: function(e){
alert('Error: ' + e);
}
});
$.mobile.changePage('test.html', { transition:"slide" ,changeHash : true });
Test.html 显示代码
<div data-role="content">
<ul data-role="listview" id="pollChallengeVoterList" data-divider-theme="b" data-inset="true"></ul>
</div>
<script type="text/javascript" src="js/test.js"></script>
test.js 代码
var strDataResult = hasInStorage("PollChallengeCount",PollChallengeVoterList);
var strDataList = '';
$("#pollChallengeVoterList").html(strDataList);
var arrMainDataDetail = getArrayStorage(PollChallengeVoterList);
var intDataCount = arrMainDataDetail.pollChallengeCount;
for(j = 0; j < intDataCount; j++)
{
var intClmId = arrMainDataDetail.CLMid;
var intCvdId = arrMainDataDetail[j].CVDId;
var intCltId = arrMainDataDetail[j].CLTId;
var intPollChallengeVoterId = arrMainDataDetail[j].VoterId;
if(arrMainDataDetail[j].Voted == 0)
{
var intFlg = 1;
}
else
{
var intFlg = 0;
}
if(arrMainDataDetail[j].Challenged==1)
{
var strChallengedColor = "#9F1335" ;
}
else
{
var strChallengedColor = "" ;
}
if(arrMainDataDetail[j].AptUnitNo == "")
{
strAddressRecord =arrMainDataDetail[j].AddressLine1;
}
else
{
strAddressRecord =arrMainDataDetail[j].AddressLine1+' , # '+arrMainDataDetail[j].AptUnitNo;
}
if(arrMainDataDetail[j].Challenged==1)
{
strVoterClass = "voted";
strVoterStatus ='Challenged';
}
else
{
if(arrMainDataDetail[j].Voted == 0)
{
strVoterClass = "voted";
strVoterStatus ='Voted';
}
else
{
strVoterStatus ='Undo</span><span class="ui-li-count unvoted">Voted</span>';
}
}
$('#pollChallengeVoterList').append('<li data-theme="c" data-icon="false"><a href="javascript:void(0)" style="color :'+strChallengedColor+'" data-transition="slide" onclick=ajaxupdatevote("'+intClmId+'","'+intCvdId+'","'+intCltId+'","'+intPollChallengeVoterId+'","'+intFlg+'","'+j+'")>'+arrMainDataDetail[j].LastName+', '+arrMainDataDetail[j].FirstName+'<span class="address" style="color :'+strChallengedColor+'">'+strAddressRecord+'</span><span class="ui-li-count '+strVoterClass+'">'+strVoterStatus+'</span></a></li>');
}
$("#pollChallengeVoterList").listview("refresh");