使此函数基于表格进行无限嵌套。

我最终解决了在魔兽世界中创建表格下拉菜单的问题。

现在我需要能够将其嵌套到用户提供的较深层次。我该怎么做?

这是我目前使用的功能:

     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"}}}

它目前可以设置到两个下级菜单。第一级和子菜单。

有人能帮帮我吗?

点赞
用户2699577
用户2699577

以下是解决方案:

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 = {{"问候", true, {{"您好", true, {{"你", true, {{"棒极了", false, nil}}},{"好", false, nil}}},
                                     {"您好", false, nil}}},
                {"告别", true, {{"再见", false, nil},
                                     {"再见", false, nil}}},
                {"测试", false, nil}}
2014-06-11 00:42:54