Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 电子工业中的工控机通信问题_Javascript_Sql_Sqlite_Electron - Fatal编程技术网

Javascript 电子工业中的工控机通信问题

Javascript 电子工业中的工控机通信问题,javascript,sql,sqlite,electron,Javascript,Sql,Sqlite,Electron,我正在构建一个应用程序,它基本上读取sqlite3数据库文件。我有两个渲染过程。这两个渲染进程都是在主进程中创建的。第二个渲染进程是通过单击第一个渲染进程中的特定按钮创建的,第一个渲染进程将在该进程上向主进程发送ipcRenderer.send()消息 我的代码能够创建第二个渲染过程,但无法访问它应该获得的数据。这是我的第一个问题,很抱歉它缺少一些协议 第一个片段是主进程(app.js)中的代码 //第二个片段是第一个渲染过程 ipcRenderer.on('query:ResultRo

我正在构建一个应用程序,它基本上读取sqlite3数据库文件。我有两个渲染过程。这两个渲染进程都是在主进程中创建的。第二个渲染进程是通过单击第一个渲染进程中的特定按钮创建的,第一个渲染进程将在该进程上向主进程发送ipcRenderer.send()消息

我的代码能够创建第二个渲染过程,但无法访问它应该获得的数据。这是我的第一个问题,很抱歉它缺少一些协议

第一个片段是主进程(app.js)中的代码

//第二个片段是第一个渲染过程

    ipcRenderer.on('query:ResultRows',(event,rows) => {

   var btn = document.createElement("BUTTON");
   var t = document.createTextNode(rows[0].name);
   btn.appendChild(t);
   document.body.appendChild(btn);

   var test = rows;
   btn.addEventListener('click', function() {

   ipcRenderer.send('show:popUpContents', test);

   console.log(rows);


   });
   });
现在,主进程(app.js)将侦听第二个代码段

    ipcMain.on('show:popUpContents',(event,test) =>{

    popWindow = new BrowserWindow({ });


    popWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'pop-up.html'),
    protocol: 'file:',
    slashes: true
    }));


    popWindow.webContents.send('get:popUpContents', test);
    console.log(test);
    console.log(popWindow.webContents);
    popWindow.webContents.openDevTools();
    });
//现在,第二个渲染进程打开,但它无法访问“test”变量,也无法在块内打印console.log


一天后,我自己设法解决了这个问题。您需要等待新浏览器窗口的“准备加载”事件,然后才能使其侦听传入消息

    ipcMain.on('show:popUpContents',(event,test) =>{

    popWindow = new BrowserWindow({ });


    popWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'pop-up.html'),
    protocol: 'file:',
    slashes: true
    }));


    popWindow.webContents.send('get:popUpContents', test);
    console.log(test);
    console.log(popWindow.webContents);
    popWindow.webContents.openDevTools();
    });
     ipcRenderer.on('get:popUpContents',(event,test) => {
     debugger;
     console.log(test);
     console.log('hellow world');
   });
   console.log('outside function');