数据库 - phonegap前的页面 [英] page before database - phonegap
问题描述
我有一个页面必须显示来自webql数据库的信息。
但是,即使信息位于数据库中,页面也会加载空格。我猜在打开/激活数据库之前填充页面?
有什么我可以做到这一点,减缓页面加载或加快数据库加载吗?
I have a page that has to display information from a websql database. However the page loads with blanks, even though the information is in the database. I am guessing that the page gets populated before the database is open / active? Is there anything I can do so slow the page load or speed up the database load?
推荐答案
与同样的问题。下面是示例db服务功能代码。
I was struggling with the same issue. Below is the sample db service function code.
这是因为web-sql调用是异步的。例如,下面的getItemData是在mapItemRow将结果集转换为所需对象类型之前返回itemData。
Reason this was happening because web-sql calls are asynchronous. For example, below getItemData is returning itemData before mapItemRow converts the resultset into required object type.
getItemData:function(){
var itemData= [];
_dbCon.transaction(function (tx) {
var queryExp = 'SELECT description as Item, amount as Amount from inventory';
tx.executeSql(queryExp, [],mapItemRow);
}, dbConnectionFactory.errorDBSql, dbConnectionFactory.successDBSql);
function mapItemRow(tx, results) {
console.log('Calling mapItemRow....')
var len = results.rows.length;
for (i = 0; i < len; i++) {
itemData.push({ITEM: results.rows.item(i).description, Amount: results.rows.item(i).amount});
}
return itemData;
};
}
我也使用angularJs来解决这个问题我使用$ q和promise功能。让我知道,如果你有兴趣看到的解决方案。
I am also using angularJs so to fix this problem i used $q and promise functionality. Let me know if you are interested to see the solution.
在您的情况下,您可以使用settimeout功能:
In your case you can use settimeout functionality:
var millisecondsToWait = 500;
setTimeout(function() {
// call your db service
}, millisecondsToWait);
您还可以实现像以下链接中提到的解决方案:
等到条件成立为止?
You can also implement solution like waitfor mentioned in following link: Wait until a condition is true?
希望这可以帮助你。
这篇关于数据库 - phonegap前的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!