右键单击 table 行时如何显示电子上下文菜单
How to show electron context menu upon right click on table row
我正在尝试学习 Electron 并构建一个简单的应用程序。在 HTML 部分,我有 table 和一些行。
我使用 "electron-context-menu" NPM 包创建了上下文菜单。现在我希望当我右键单击 table 的任意行时会弹出一些菜单,例如删除行。
例如,我有如下一行:
<tr>
<td id="name-1"></td>
<td id="prog-1"><progress id='progress-1' max='100' value='0'> </progress></td>
<td id="size-1"></td>
<td id="status-1"></td>
<td style="display:none;" id="path-1"></td>
<td style="display:none;" id="link-1"></td>
<td style="display:none;" id="formatid-1"></td>
</tr>
现在,当我右键单击该行时,只会出现删除行菜单,单击该菜单后,我想调用一个函数 deleteRow(this)
来删除该行。
对于动态添加和删除行,我使用的代码来自:
有什么帮助吗?另外,如何获取行中元素的id?
回调后添加false
参数
new_row.addEventListener('contextmenu', function(e){
var t = e.srcElement.id.split('-');
id = t[1];
menu.popup(remote.getCurrentWindow());
}, false);
我自己找到了答案:
const menu = new Menu();
menu.append(new MenuItem({
label: 'Resume', click(){
console.log('resume clicked');
}
}));
menu.append(new MenuItem({type: 'separator'}));
menu.append(new MenuItem({
label: 'Pause', click(){
console.log('item 2 clicked');
}
}));
以及我添加动态行的位置:
new_row.addEventListener('contextmenu', function(e){
var t = e.srcElement.id.split('-');
id = t[1];
menu.popup(remote.getCurrentWindow());
});
我正在尝试学习 Electron 并构建一个简单的应用程序。在 HTML 部分,我有 table 和一些行。
我使用 "electron-context-menu" NPM 包创建了上下文菜单。现在我希望当我右键单击 table 的任意行时会弹出一些菜单,例如删除行。
例如,我有如下一行:
<tr>
<td id="name-1"></td>
<td id="prog-1"><progress id='progress-1' max='100' value='0'> </progress></td>
<td id="size-1"></td>
<td id="status-1"></td>
<td style="display:none;" id="path-1"></td>
<td style="display:none;" id="link-1"></td>
<td style="display:none;" id="formatid-1"></td>
</tr>
现在,当我右键单击该行时,只会出现删除行菜单,单击该菜单后,我想调用一个函数 deleteRow(this)
来删除该行。
对于动态添加和删除行,我使用的代码来自:
有什么帮助吗?另外,如何获取行中元素的id?
回调后添加false
参数
new_row.addEventListener('contextmenu', function(e){
var t = e.srcElement.id.split('-');
id = t[1];
menu.popup(remote.getCurrentWindow());
}, false);
我自己找到了答案:
const menu = new Menu();
menu.append(new MenuItem({
label: 'Resume', click(){
console.log('resume clicked');
}
}));
menu.append(new MenuItem({type: 'separator'}));
menu.append(new MenuItem({
label: 'Pause', click(){
console.log('item 2 clicked');
}
}));
以及我添加动态行的位置:
new_row.addEventListener('contextmenu', function(e){
var t = e.srcElement.id.split('-');
id = t[1];
menu.popup(remote.getCurrentWindow());
});