Am用electronic js构建一个桌面应用程序,并尝试在渲染器过程中使用细枝显示json对象
我做了一个按钮来触发index.html.twig文件中的事件
<body>
<div class="mainWrapper">
<h1>CRUD from DB</h1>
<button id="sendBtn">Send Event</button>
{% for item in items %}
<h1>{{ grant.grant_name }}</h1>
{% endfor %}
</div>
<script>require('./../index.js');</script>
</body>
我捕获了渲染器index.js中的按钮单击并发送了事件
const sendBtn = document.getElementById('sendBtn');
sendBtn.addEventListener('click', () => {
// send event from renderer process to main process
ipc.send('send-to-main');
});
// capture reply
ipc.on('send-reply', (event, arg) => {
// arg is the reply from main process
console.log(arg);
twig.view = { items: arg };
});
在我的主要流程中,我使用json对象发送回信
// listen to event with ipc and display dialog box
ipc.on('send-to-main', (event) => {
// reply to event
let msg = [
{ id: 1, grant_name: 'Grant 1' },
{ id: 2, grant_name: 'Grant 2' },
{ id: 3, grant_name: 'Grant 3' }
];
event.sender.send('send-reply', msg);
});
我试图显示对象授予名称,但不起作用