我正在构建一个应用程序,基本上读取一个sqlite3数据库文件。我有两个渲染进程。两个渲染进程都是在主进程中创建的。第二渲染进程是通过在第一渲染进程中点击特定按钮来创建的,第一渲染进程在该按钮点击后向主进程发送ipcRenderer.send()消息。
我的代码能够创建第二个呈现进程,但它无法访问它应该获得的数据。这是我的第一个问题,我很抱歉它缺乏一些协议。
第一个代码片段是主进程中的代码(app.js)
database.all(`SELECT _table_Name as name, _table_json as json
FROM _table_main WHERE _table_Name = "EWS Equipment Status Recording"`, (err, rows) => {
if (err) {
console.log(err.message);
}
mainWindow.webContents.send('query:ResultRows', rows);
});//第二个片段是第一个渲染过程
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();
});//现在第二个呈现进程打开,但它不能访问‘console.log’变量,也不能打印块内的测试。enter image description here
ipcRenderer.on('get:popUpContents',(event,test) => {
debugger;
console.log(test);
console.log('hellow world');
});
console.log('outside function');发布于 2018-06-28 22:43:12
一天后,我设法自己解决了这个问题。用户需要等待新浏览器窗口的“准备加载”事件,然后才能使其侦听传入的消息。
https://stackoverflow.com/questions/51056310
复制相似问题