我想在數據庫中插入數據時,該設備是在線,如果該設備是離線我要顯示存儲在數據庫中的數據顯示,它在離線。Phonegap-插入數據,並使用數據庫
目前這裏我分析從RSS源中的數據和數據庫中插入數據時,該設備在線和我不能顯示當設備成爲offline.And也是我試過很多次,以顯示數據相同的數據使用以下代碼:
document.addEventListener("offline", yourCallbackFunction, false);
$.each(data.responseData.feed.entries, function (e, item) {
var titles=item.title;
var linked=item.link;
s += '<li><div class="itemTitle"><a href="' + item.link + '" target="' + def.TitleLinkTarget + '" >' + item.title + "</a></div>";
if (def.ShowPubDate) {
i = new Date(item.publishedDate);
s += '<div class="itemDate">' + i.toLocaleDateString() + "</div>";
}
if (def.ShowDesc) {
if (def.DescCharacterLimit > 0 && item.content.length > def.DescCharacterLimit) {
s += '<div class="itemContent">' + item.content.substr(0, def.DescCharacterLimit) + "...</div>";
}
else {
s += '<div class="itemContent">' + item.content + "</div>";
console.log(s);
}
}
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Populate the database
//
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (title, desc)');
tx.executeSql('INSERT INTO DEMO (title, desc) Values(?,?)',[titles,s]);
}
// Query the database
//
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
// Query the success callback
//
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("DEMO table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " ID = " + results.rows.item(i).title + " Data = " + results.rows.item(i).desc);
$("#apps ul").append('<li><a href="results.rows.item(i).desc"><span class="tab">' +results.rows.item(i).desc+'</span></a></li>');
}
}
document.addEventListener("offline", querySuccess, false);
嗨我更新我的示例代碼now.can你現在看到它,幫助我一個新的phonegap – Ram