MenuItems are ephemeral objects that are instantiated by their owner Menu objects, with the Menu.items property. It is not recommended to use a MenuItem that have been previously removed.
MenuItem:remove() method
Removes the MenuItem from the Menu it belongs to.
Return value
This method returns no value.Example
local ui = require "ui"
-- create a simple Window
local win = ui.Window("MenuItem:remove() sample", 316, 246)
local button = ui.Button(win, "Remove 'Items'", 100, 86)
-- create a Window menu
win.menu = ui.Menu("Stock", "Commands")
-- insert a "Items" submenu at second position
win.menu:insert(2, "Items", ui.Menu("Item 1", "Item 2", "Item 3")).submenu.onClick = function (self, item)
ui.info("You have clicked on "..item.text)
end
-- remove "Items" submenu
function button:onClick()
win.menu.items[2]:remove()
end
-- shows the Window
win:show()
-- update user interface
repeat
ui.update()
until not win.visible