現状
ElectronのメインプロセスにおいてwebContents.sendでオブジェクトを送信するとレンダラープロセスに[Object]という展開可能なプロパティのようなものが表示される。
ゴール
出てくるオブジェクトを想定しているメッセージ(送った文字列のみ)にしたい
コード
上から順に メインプロセス、レンダラープロセス、データベース内容、表示されるオブジェクト
Javascript
1//メインプロセス 2function get() { 3 db.find({}, (error, docs) => { 4 console.log(docs[0].notes); 5 return docs[0].notes; 6 }); 7}; 8 9const createWindow = () => { 10 // Create the browser window. 11 const mainWindow = new BrowserWindow({ 12 width: 800, 13 height: 600, 14 webPreferences: { 15 nodeIntegration: true, 16 contextIsolation: false, 17 }, 18 }); 19 20 mainWindow.webContents.once('did-finish-load', () => { 21 mainWindow.webContents.send('message', get() ); 22 }); 23 24 // and load the index.html of the app. 25 mainWindow.loadFile(path.join(__dirname, 'index.html')); 26 27 // Open the DevTools. 28 mainWindow.webContents.openDevTools(); 29 mainWindow.setMenu(null); 30};
Javascript
1//レンダラープロセス 2ipcRenderer.on('message', (message) => { 3 console.log(message); 4}
db
1{"notes":"a","date":{"$$date":1648183077589},"_id":"Cq7THhdzCMz4rmui"} 2
Javascript
1//表示されるもの 2{ 3 "sender": { 4 "_events": {}, 5 "_eventsCount": 1 6 }, 7 "senderId": 0, 8 "ports": [] 9} 10//更に展開可能
ご回答よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー