如何使子下拉列表显示在默认(折叠)结构中

时间:2018-05-04 06:27:24

标签: javascript html

我有一个带有多个下拉列表的下拉列表,可以在其他点击时打开和关闭,但是当我尝试重新打开下拉列表时,整个点都会显示而不会关闭。如何使其显示在默认结构上。 请帮帮我们提前致谢

function index(dataItem) {

    var grid = $("#grid").data("kendoGrid");
    var gridData = grid._data;
    console.log("gridData>>", gridData);
    console.log("dataItem>>", dataItem);

    if (grid.dataItem(grid.select()) != null || grid.dataItem(grid.select()) != undefined) {
        selectedItem = grid.dataItem(grid.select());
        console.log("selectedItem>>", selectedItem.ProviderTypeName);

        for (item in gridData) {
            console.log("grid[item].ProviderTypeName>>", gridData[item].ProviderTypeName);
            console.log("selectedItem", selectedItem.ProviderTypeName);
            if (gridData[item].ProviderTypeName == selectedItem.ProviderTypeName && gridData[item].Id != selectedItem.Id) {
                //e.preventDefault();
                grid.bind("dataBinding", function (e) { e.preventDefault(); });
                grid.unbind("dataBinding");
                grid.refresh();
                alert("Duplicates not allowed");
                return false;
            }
        }
    }
    return true;
}

1 个答案:

答案 0 :(得分:0)

单击修改后的类时:

enter image description here

答案,删除"打开"下拉菜单中的课程。

        <ul class="dropdown-menu ">
            <li>
                <a tabindex="-1" href="#">2nd level dropdown</a>
            </li>
            <li>
                <a tabindex="-1" href="#">2nd level dropdown</a>
            </li>
            <li class="dropdown-submenu">
                <a class="test" href="#">Another dropdown
                    <span class="caret"></span>
                </a>
                <ul class="dropdown-menu ">
                    <li>
                        <a href="#">3rd level dropdown</a>
                    </li>
                    <li>
                        <a href="#">3rd level dropdown</a>
                    </li>
                </ul>
            </li>
        </ul>

替换以下的jQuery代码:

    $('.dropdown').on('hidden.bs.dropdown', function () {
        $('.dropdown-submenu a.test').each(function () {
            var ul = $(this).next('ul');
            if (ul.hasClass('opened')) {
                ul.removeClass('opened').addClass('closed');
            } else {
                ul.addClass('opened').removeClass('closed');
            }
            if ($(this).parents('ul').length) {
                $(this).parents('ul').find('ul').not(ul).addClass('closed').removeClass('opened')
            }
            e.stopPropagation();
            e.preventDefault();
        });
    });