这是解决方案:
function IOLib_CreateDropDown(parent, name, title, width, anchor, posX, posY, menuList, OnClick)
local dropDown = CreateFrame("Button", name, parent, "UIDropDownMenuTemplate")
--_G[name].list = menuList
dropDown.list = menuList
-- dropDown.Func = OnClick
dropDown:ClearAllPoints()
dropDown:SetPoint(anchor, posY, posX)
local function initialize(self, level)
local info = UIDropDownMenu_CreateInfo()
if level ~= nil then
info = UIDropDownMenu_CreateInfo()
info.text = title
info.isTitle = true
UIDropDownMenu_AddButton(info, level)
if level == 1 then
for a,b in pairs(menuList) do
info = UIDropDownMenu_CreateInfo()
info.text = b[1]
info.hasArrow = b[2]
info.func = OnClick
if info.hasArrow then _menuLists[b[1]] = b[3] end
UIDropDownMenu_AddButton(info, level)
end
elseif level > 1 then
--print(#_menuLists[UIDROPDOWNMENU_MENU_VALUE][2])
--for x=1, #_menuLists[UIDROPDOWNMENU_MENU_VALUE] do
for a,b in pairs(_menuLists[UIDROPDOWNMENU_MENU_VALUE]) do
info = UIDropDownMenu_CreateInfo()
info.text = b[1]
info.hasArrow = b[2]
if info.hasArrow then _menuLists[b[1]] = b[3] end
info.func = OnClick
UIDropDownMenu_AddButton(info, level)
end
end
end
end
UIDropDownMenu_Initialize(dropDown, initialize)
UIDropDownMenu_SetWidth(dropDown, width) -- Use in place of dropDown:SetWidth
UIDropDownMenu_SetButtonWidth(dropDown, width + 24)
UIDropDownMenu_SetSelectedID(dropDown, 1)
UIDropDownMenu_JustifyText(dropDown, "LEFT")
return dropDown
end
这是与此函数一起使用的表的示例:
testMenuList = {{"Greetings", true, {{"Hi", true, {{"H", true, {{"Amazing", false, nil}}},{"i", false, nil}}},
{"Hello", false, nil}}},
{"Farewells", true, {{"Bye", false, nil},
{"Goodbye", false, nil}}},
{"Test", false, nil}}