我试图在localstorage中缓存JSON数据,以便在没有互联网连接时加载它.它工作正常,但当我重新启动应用程序时,我认为本地存储已清除
这是我的代码:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("offline", function() {
alert("No internet connection");
$.each(JSON.parse(localStorage.getItem('foo')), function(key, val) {
if(!(val.php)){val.php=0;}
$('ul.get-mertchant').append('<li> <a href="azkadenya.html?id=' + val.nid + '&nop='+ val.php +'" class="li-link"><div class="circle-img"><img src="'+ val.logo + '" /></div><div class="merchant-info"><h1>'+ val.node_title +'</h1><p>You Have '+ val.php +' Binggz</p></div><div class="more-icon"></div></a> </li>');
});
}, false);
$.getJSON('mywebsite/views/services_merchant_mobile', function(data) {
localStorage.setItem('foo', JSON.stringify(data));
var items = [];
$.each(JSON.parse(localStorage.getItem('foo')), function(key, val) {
if(!(val.php)){val.php=0;}
$('ul.get-mertchant').append('<li> <a href="azkadenya.html?id=' + val.nid + '&nop='+ val.php +'" class="li-link"><div class="circle-img"><img src="'+ val.logo + '" /></div><div class="merchant-info"><h1>'+ val.node_title …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的ios phonegap应用程序上设置facebook connect插件,我按照以下链接中的步骤操作
https://github.com/phonegap/phonegap-facebook-plugin
并完成它100%,但当我运行应用程序它在控制台中显示此错误
2013-04-24 13:43:10.009 ShoBingg[2538:19a03] CDVPlugin class FacebookConnectPlugin (pluginName: org.apache.cordova.facebook.Connect) does not exist.
2013-04-24 13:43:10.010 ShoBingg[2538:19a03] ERROR: Plugin 'org.apache.cordova.facebook.Connect' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2013-04-24 13:43:10.010 ShoBingg[2538:19a03] -[CDVCommandQueue executePending] [Line 103] FAILED pluginJSON = ["org.apache.cordova.facebook.Connect467591405","org.apache.cordova.facebook.Connect","init",["427370550688587"]]
2013-04-24 13:43:10.010 ShoBingg[2538:19a03] CDVPlugin class FacebookConnectPlugin (pluginName: org.apache.cordova.facebook.Connect) does not exist.
2013-04-24 13:43:10.010 ShoBingg[2538:19a03] ERROR: Plugin 'org.apache.cordova.facebook.Connect' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2013-04-24 13:43:10.010 ShoBingg[2538:19a03] -[CDVCommandQueue …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 JS 生成 6 位代码。
它必须包含 3 个数字和 3 个字符。
这是我的代码
var numbers = "0123456789";
var chars = "acdefhiklmnoqrstuvwxyz";
var string_length = 3;
var randomstring = '';
var randomstring2 = '';
for (var x = 0; x < string_length; x++) {
var letterOrNumber = Math.floor(Math.random() * 2);
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
for (var y = 0; y < string_length; y++) {
var letterOrNumber2 = Math.floor(Math.random() * 2);
var rnum2 = Math.floor(Math.random() …Run Code Online (Sandbox Code Playgroud) 我有$.eachFacebook好友列表.
这是$.each代码
$.each(response.data, function(index,friend) {
alert(friend.name + ' has id:' + friend.id);
}
Run Code Online (Sandbox Code Playgroud)
现在我如何将这些数据存储在数组中,就像这个数组一样
friends = [
{ "name": "John" , "id": "1" },
{ "name": "Anna" , "id": "2" },
{ "name": "Peter" , "id": "3" }
];
Run Code Online (Sandbox Code Playgroud) 如何使用foreach创建这样的数组
$data = array(
(object)array(
'oV' => 'myfirstvalue',
'oT' => 'myfirsttext',
),
(object)array(
'oV' => 'mysecondvalue',
'oT' => 'mysecondtext',
),
);
Run Code Online (Sandbox Code Playgroud)