我们有一个应用程序与cordova [phonegap] 我们希望将结果脱机保存到缓存中
结果来自服务器[PHP] 比使用ajax& webview中显示的javascript结果
当用户处于离线模式[no wifi / 3G]时,我尝试使用localStorage来保留上次使用的值[2]。 USD / EURO或USD / ILS,即
使用jQuery 通常有效
$('.loading').fadeOut();
var $response = $(result);
var result = $response.filter('#result').html();
var result_1 = $response.filter('#result_1').html();
var result_10 = $response.filter('#result_10').html();
var result_100 = $response.filter('#result_100').html();
var result_1000 = $response.filter('#result_1000').html();
$('.convertfrom_txt').each(function() { $(this).text(cfrom_str); })
$('.convertto_txt').each(function() { $(this).text(cto_str); })
$('#cresult').text(result + ' ' + cto_str);
$('#one_unit').text(result_1);
$('#ten_unit').text(result_10);
$('#hundred_unit').text(result_100);
$('#thousand_unit').text(result_1000);
离线假设每天都有价值变化。 [货币]
var currency = [10]; //10 currencies max to save offline
var currency = result_1 ; //save result of 1 coin to array
var offline;
//Check connection
function onDeviceReady() {
var offlineData = window.localStorage.getItem("result_1");
if (window.navigator.onLine) offline = false;
}
if (offline == false)
{
document.getElementById('result_1').value = "currency[0]";
document.getElementById('result_10').value = "currency[0]*10";
document.getElementById('result_100').value = "currency[0]*100";
document.getElementById('result_1000').value = "currency[0]*1000";
document.getElementById('time').value = "time";
}
result_1表示一次转化的值。 我们希望在一个数组中离线存储1美元和1欧元的值
我不确定选择哪种更好的方法
localStorage采取官方形式 Docs
var storage = localStorage;
var value = storage.getItem(key); // Pass a key name to get its value.
storage.setItem(key, value) // Pass a key name and its value to add or update that key.
storage.removeItem(key) // Pass a key name to remove that key from storage.
由于