jQueryUI 菜单小部件:collapseAll 不会折叠所有子排序层

jQueryUI Menu widget: collapseAll does not collapse all subordered layers

我在处理 jqueryUI 菜单小部件时出现错误行为。

查看以下代码片段和下面的菜单方案: 如您所见,菜单打开到第三层。我的意图是只需单击一下鼠标即可关闭整个第二个菜单项。所以我想点击“项目 2”,所有对应的子项目都应该折叠起来 (2.x, 2.x.x)。 不幸的是,我目前必须在主菜单项上单击两次才能实现此目的。

项目 1

-- 项目 1.1

项目 2

-- 项目 2.1

-- 项目 2.2

--- 项目 2.2.1

--- 项目 2.2.2

--- 项目 2.2.3

-- 项目 2.3

负责的职能结构如下:

 collapseAll: function (event, all) {
            clearTimeout(this.timer);
            this.timer = this._delay(function () {
                // If we were passed an event, look for the submenu that contains the event
                var currentMenu = all ? this.element :
                    $(event && event.target).closest(this.element.find(".ui-menu"));

                // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
                if (!currentMenu.length) {
                    currentMenu = this.element;
                }

                this._close(currentMenu);

                this.blur(event);
                this.activeMenu = currentMenu;
            }, this.delay);
      }

,

有什么想法吗?

我修复了这个错误。这种行为的原因不是 collapseAll-function,而是由此调用的关闭函数。

使用此代码现在可以使用了:

_close: function( startMenu ) {
    if ( !startMenu ) {
        startMenu = this.active ? this.active.parent() : this.element;
    }

    startMenu
        .find( ".ui-menu" )
        .hide()
        .attr( "aria-hidden", "true" )
        .attr( "aria-expanded", "false" )
        .end()
        .find( ".ui-state-active" )//.not( ".ui-state-focus" )
        .removeClass( "ui-state-active" );
},