我使用jQuery Mobile和PhoneGap的(Apache的科尔多瓦)建立一个移动应用程序,问题是,首先我需要一个数据库查询之前,我决定我想先加载,如果是“登录”页面的页面或“主页”。如何决定首先在jquery mobile上加载哪个页面?
基于PhoneGap的文件,我需要绑定的“deviceready”事件,知道什么时候该设备已准备就绪,然后使DB查询上。
document.addEventListener("deviceready", onDeviceReady, false);
称为“onDeviceReady”功能创建DB如果它不是创建,然后做一个查询到一个名为“用户”表,如果有一个或多个用户我wan't显示一个名为“页main.html“,否则一个名为”login.html“的页面。
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(populateDB, errorCB, successCB);
}
基本上,问题是,虽然该功能被执行时,因为执行以下的代码的第一页被载入被称为“onDeviceReady”功能之前:
$(document).bind("mobileinit", function(){
$.mobile.listview.prototype.options.filterPlaceholder = "Buscar...";
//-> patch for phonegap
$.mobile.allowCrossDomainPages = true;
$.mobile.page.prototype.options.backBtnText = "atrás";
});
$(document).bind("pagebeforeload", function(event, data){
// here i think i would say to phone gap not to load any page until i make the db queries
//i think i can't make the DB queries here because the "pagebeforeload" is launched before the "deviceready" function
});
如果的代码根据ASC顺序DOM此页面加载第一页:
<div data-role="page" id="page-init">
<div data-role="header" data-theme="c" data-position="fixed">
<h1>Init page</h1>
</div><!-- /header -->
</div>
如果我改变页面为“main.html中”使用$.mobile.changePage("main.html");
一次我检查,如果有一个或更多的用户记录在“用户”表上,“页面初始化”页面首先加载,然后“main.html”,我不想这样做,因为用户可以选择一种闪光。 我只是想决定一次,我检查了“用户”表,该页面将首先显示。
不能相信这个解决方案从来没有起床投票!同时使用加载页面和此解决方案可以工作,但上述解决方案的问题在于它将使用#标记设置页面。工作,但将网址更改为http://example.com#my-page,这是可以的,除非你想隐藏用户的散列(就像我的情况一样) –