[英]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.