javascript - 在 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
解决方案
推荐阅读
- python - 在运行时重置/重新加载嵌套类的类属性
- spring-boot - 如何将包含 spring-hateoas 版本 1.0.0.M1 的 spring-boot-hateoas-starter 包含到我的项目中
- functional-programming - 简单的 HTML 代码并将 CSS、Python 和 JavaScript 与现有的 HTML 代码集成
- marklogic - 如何根据 MarkLogic 中元素或其他属性的关联值按属性进行选择性排序
- c++ - 使用 ROS2 环境变量创建 C++ 项目
- dc.js - 从 dc.js 中的用户输入构建折线图
- sql - 如何按条件分组?
- react-native - 如何将库的本地副本添加和编译到 Android React Native 模块中?
- javascript - 如何将 args[1] 转换为日期以输入 MySQL DB(Javascript,DiscordJS)?
- c# - 生成的 nuget 包中缺少项目 .dll 本身