【发布时间】:2014-01-22 16:35:49
【问题描述】:
在我的 jQuery 手机 Phonegap 应用程序中,我有一个页面,其中有一个列表视图,此列表内容是动态添加的,问题是当我导航到此页面时,它首先显示为空,几秒钟后添加了列表视图到页面并显示,我使用 pagebeforeshow 事件在显示页面之前添加列表视图内容,但它对我不起作用“列表视图在显示页面后显示”并且用户会注意到并看到内容同时它添加到页面。我该如何解决这个问题,以便在显示页面之前添加列表内容?请帮帮我..
提前致谢。
HTML
<body>
<div data-role="page" id="EmployeesListPage">
<div data-role="header" data-position="fixed" data-tap-toggle="false" data- fullscreen="false" data-theme="b">
<h3> Employees</h3>
</div>
<div data-role="content">
<ul data-role="listview" id="EmpList" data-inset="true" data-filter="true" data- filter-placeholder="Search " data-split-icon="delete" style="margin-top: 30px;" >
</ul>
</div>
</div>
</body>
Java 脚本
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady()
{
loading('show');
$('#EmployeesListPage').on( 'pagecreate',function(event){
db.transaction(getAllEmployees, transactionError);
});
}
function getAllEmployees(tx)
{
tx.executeSql('SELECT EmpName,Salary,Gender,Country FROM Employee', [],getEmpSuccess,transactionError);
}
function getEmpSuccess(tx,result)
{
if (result.rows.length)
{
for(var i=0;i< result.rows.length; i++)
{
var row = result.rows.item(i);
$('#EmpList').append('<li><a href="#">' +'<font class="line1">' + ' '+row['EmpName'] + '</font><BR><BR>' +'<font size="6px" class="line2" > '+ row['Gender'] +'</font>'+'<font size="6px" class="line3"> ' +row['Country']+' </font>'+'<font size="6px" class="line4"> '+ row['Salary']+'</font><BR> '+'</a><a href="#" >Delete</a></li>' );
}
$('#EmpList').listview('refresh');
loading('hide');
}
}
function transactionError(tx, error)
{
alert("Database Error: " + error);
}
function loading(SH)
{
setTimeout(function(){
if( SH == "show")
{
$.mobile.loading( "show", {
text:"Loading...",
textVisible: true,
theme: "b",
textonly: false
});
}
else if( SH == "hide")
{
$.mobile.loading("hide");
}
}, 1000);
}
【问题讨论】:
-
使用
pagecreate事件。 -
@OmarThanks,我已经尝试过了,但问题仍然存在
-
@Omar 这个问题还有其他解决方案吗?
-
@Omar 你能帮帮我吗??
-
试试
pagebeforechange。请注意,转换速度很快,从服务器检索数据可能需要一些时间。
标签: jquery-mobile cordova jquery-mobile-listview