我终于解决了我的问题,使魔兽世界的下拉菜单的表格。
现在我需要它能够在用户提供的范围内嵌套。我该怎么做呢?
下面是我当前使用的函数:
local info = UIDropDownMenu_CreateInfo()
if level == 1 then
for a,b in pairs(menuList) do
info.text = b[1]
info.hasArrow = b[2]
UIDropDownMenu_AddButton(info, level)
end
elseif level == 2 then
for a,b in pairs(menuList[UIDROPDOWNMENU_MENU_VALUE][3]) do
info.text = b
info.func = OnClick
UIDropDownMenu_AddButton(info, level)
end
end
下面是使用的表格示例:
testMenuList = {Greetings = {"Greetings", true, {"hi", "hello", "good day"}}, Farewells = {"Farewells", true, {"bye", "goodbye", "later"}}}
它可以设置当前最多2个级别。第一个和子菜单。
有谁能帮我吗?解决方案如下:
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}}