I create a context menu on application start up
<code class="js>
function doCreateMiscUI() {
webix.ui({
view: "contextmenu",
autowidth: true,
id: "actionMenu",
on: {
"onItemClick": (id: string, e: MouseEvent,
node: HTMLElement) => {
Actions.doExecutePowerAction(id);
},
"onBeforeShow": () => {
actionMenu.refresh();
}
}
});
actionMenu = $$("actionMenu") as webix.ui.contextmenu;
}
`
I then want to manipulate the context menu items and show it on a button click event.
<code class="js>
function onPowerButtonClick(e: any, id: any) {
// Clear action menu data.
actionMenu.clearAll();
// Get selected item.
let selItem = rxGrid.getSelectedItem();
// Populate action menu data.
if (selItem instanceof Types.Receiver) {
actionMenu.add({ id: "self", value: "Restart: "
+ selItem.name, icon: "fa fa-sign-in" });
if (selItem.assignedtx_combo_value !== "") {
actionMenu.add({
id: "assignedtx", value: "Restart: "
+ selItem.assignedtx.name.toString().toUpperCase(),
icon: "fa fa-sign-out"
});
actionMenu.add({ id: "both", value: "Restart:
Both", icon: "fa fa-asterisk" });
actionMenu.add({ $template: "Separator" });
actionMenu.add({
id: "computer", value: "Attached computer",
icon: "fa fa-desktop", submenu: [
{ id: "computer_restart", value: "Restart" },
{ id: "computer_poweron", value: "Power on" },
{ id: "computer_softpoweron", value: "Soft power on" },
{ id: "computer_poweroff", value: "Power off" }
]
});
}
}
actionMenu.refresh();
actionMenu.show(e.target, { x: -11, y: 10 });
}
`
The context menu shows correctly the first time i click a power button , but when if i then click another power button, the context menu does not change content. If i then click a third power button, the content is changed to content of the second button click. It seems the content is lacking behind by one.
- Click power button A => content OK.
- Click power button B => content = power button A
- Click power button C => content = power button B
etc…etc.