首页 > 解决方案 > 在 Electron 中的页面之间切换时如何防止排空数组?

问题描述

我的 Electron 应用程序在运行时会创建一个空数组。该数组用于存储有关应在test.html页面上显示的用户的一些信息。由于默认情况下该数组为空,因此我向其中添加了一些关于我自己的信息。一旦我提供了关于我自己的信息,它就会显示在test.html页面上(取自数组)。然后我转到另一个页面,当我返回时,test.html我的信息没有显示,因为数组再次为空(就像刚刚运行应用程序时一样)。如何防止清空数组?

test.html js部分

var information = require('electron').remote.getGlobal('userInfo');
window.onload = function() {
  console.log(information); // just to check if the array has been emptyfied
  if (information.length > 0) { // if I come back to the test page and my information is still stored in the array
    showInformation();
  }
}

测试.js

var infoRecords = require('electron').remote.getGlobal('userInfo');

function addInformation() {
  infoRecords = []; // if I provide information about myself then I delete the information about the previous user
  ....
  ....
  ....
  ....
  infoRecords.push(name);
  ....
  infoRecords.push(age);
  ....
  showInformation();
}

main.js

global.userInfo = []; // it's empty when the app is just run

标签: javascriptelectron

解决方案


推荐阅读