Javascript Cordova/Phonegap-关闭应用程序时储存一个数组(重新打开时使用)
我正在我的应用程序中使用数组。诸如此类 [{pseudo:“test”,id:0},{pseudo:“Lucia”,id:2}] 即使在我关闭应用程序时,我也希望保留此阵列,如何才能做到这一点? 此外,我希望在打开应用程序时直接使用它们(而不是在后台) 更新: 我试过这个 库存:Javascript Cordova/Phonegap-关闭应用程序时储存一个数组(重新打开时使用),javascript,angularjs,arrays,cordova,phonegap-plugins,Javascript,Angularjs,Arrays,Cordova,Phonegap Plugins,我正在我的应用程序中使用数组。诸如此类 [{pseudo:“test”,id:0},{pseudo:“Lucia”,id:2}] 即使在我关闭应用程序时,我也希望保留此阵列,如何才能做到这一点? 此外,我希望在打开应用程序时直接使用它们(而不是在后台) 更新: 我试过这个 库存: var ami = ({ idx: id }); var ami_json = JSON.stringify(ami); sessionStorage.setItem("ami", ami_json)
var ami = ({
idx: id
});
var ami_json = JSON.stringify(ami);
sessionStorage.setItem("ami", ami_json);
讲座仅在我第一次打开应用程序时启动(我在控制器启动后才将其放入),但我在console.log中得到空值
var amiStorage = [];
var storageAmisNotifies = window.localStorage;
var ami_json = sessionStorage.getItem("ami");
var ami = JSON.parse(ami_json);
console.log(angular.toJson(ami));
console.log(ami);
amiStorage.push(ami);
console.log(amiStorage);
console.log(angular.toJson(amiStorage));
更新2:
$scope.isChecked用于ng类,我想获取json的id,但它类似于[[{“pseudo”:pseudo,“id”:id}]]。。。
错误提示[i]。id无效
var amisNotifies = [];
$scope.isChecked = [];
var storageAmisNotifies = window.localStorage;
var ami_json = window.localStorage.getItem("info");
var ami = JSON.parse(ami_json);
if (ami != null){
amisNotifies.push(ami);
if (amisNotifies.length > 0) {
for (var i = 0; i < amisNotifies.length; i++) {
console.log(amisNotifies[[i]].id);
$scope.isChecked[amisNotifies[i].id] = "fa fa-check-circle-o pull-right";
}
}
}
var amisnotifys=[];
$scope.isChecked=[];
var storageAmisNotifies=window.localStorage;
var ami_json=window.localStorage.getItem(“info”);
var ami=JSON.parse(ami_JSON);
if(ami!=null){
amisnotifys.push(ami);
如果(amisnotifyes.length>0){
对于(变量i=0;i
尝试使用本地存储而不是会话存储
var ami = ({
idx: id
});
var ami_json = JSON.stringify(ami);
window.localStorage.setItem("ami", ami_json);
还有这里
var amiStorage = [];
var storageAmisNotifies = window.localStorage;
var ami_json = window.localStorage.getItem("ami");
var ami = JSON.parse(ami_json);
console.log(angular.toJson(ami));
console.log(ami);
amiStorage.push(ami);
console.log(amiStorage);
console.log(angular.toJson(amiStorage));
阅读localStorage API什么是StorageAmisNotifys,你以后不使用它吗?我不知道,它在你的示例中,所以我让它有两个[:[{“pseudo”:“test”,“id”:0},{“pseudo”:“Lucia”,“id”:2},{“pseudo”:“Gravestorm”,“id”:3}]]我如何获取Gravestorm的id?