![](/img/trans.png)
[英]Why memory leak happend and render slowing down when I close and re-open react component (material-table)?
[英]Cordova/Phonegap - Stock an array when I close the app (use them when I re-open)
我在我的应用程序中使用数组。 像这样的东西[{pseudo:“ test”,id:0},{pseudo:“ Lucia”,id:2}]
即使关闭应用程序,我也想保留此数组,怎么可能呢? 此外,我想在打开应用程序时直接使用它们(而不是在后台运行)
更新:我尝试过了,
库存
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-class,我想获取json的ID,但它类似于[[{“ pseudo”:pseudo,“ id”:id}]] ... amisNotify [ 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";
}
}
}
尝试使用localStorage代替sessionStorage
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.