Aurelia - A way to add a divider into a multi level drop down menu

我只是一个虾纸丫 提交于 2019-12-14 02:25:18

问题


I have a multi level dropdown menu working for Aurelia with bootstrap however whilst its three levels deep and uses as a basis THIS gist expanding on it I am having trouble adding a divider via the route settings.

Now a divider uses the class "divider" in the list tag <li></li> Ok so I thought by adding the entry divider: true in the settings for the dropdown I could check for that and instead if displaying the link etc I could instead show a divider however I dont know how to implement this into the navmenu.html file. Here is the file:

           <ul class="nav navbar-nav">
                <li repeat.for="route of router.navigation" class="${route.isActive ? 'active' : ''}">
                    <a href.bind="route.href" if.bind="!route.settings.nav"><span class="glyphicon glyphicon-${ route.settings.icon }"></span> ${route.title}</a>

                    <a href.bind="route.href" if.bind="route.settings.nav"  class="dropdown-toggle" data-toggle="dropdown">
                        <span class="glyphicon glyphicon-${ route.settings.icon }"></span> ${route.title} <span class="caret"></span> <!--First level menu heading - requires route.settings.nav to exist-->
                    </a>

                    <ul if.bind="route.settings.nav" class="dropdown-menu">

                        <li repeat.for="menu of route.settings.nav" class="dropdown-submenu">
                            <a href.bind="menu.href" if.bind="!menu.navSettings.subNav"><span class="glyphicon glyphicon-${ menu.navSettings.icon }"></span> ${menu.title}</a>

                            <a href.bind="menu.href" if.bind="menu.navSettings.subNav" class="dropdown-toggle" data-toggle="dropdown">
                                <span class="glyphicon glyphicon-${ menu.navSettings.icon }"></span> ${menu.title} <span class="caret-right"></span>
                            </a>
                            <ul if.bind="menu.navSettings.subNav" class="dropdown-menu">
                                <li repeat.for="subMenu of menu.navSettings.subNav" class="dropdown-submenu">
                                    <a href.bind="subMenu.href" if.bind="!subMenu.subNavSettings.subSubNav"><span class="glyphicon glyphicon-${ subMenu.subNavSettings.icon }"></span> ${subMenu.title}</a>

                                    <a href.bind="subMenu.href" if.bind="subMenu.subNavSettings.subSubNav" class="dropdown-toggle" data-toggle="dropdown">
                                        <span class="glyphicon glyphicon-${ subMenu.subNavSettings.icon }"></span> ${subMenu.title} <span class="caret-right"></span>
                                    </a>
                                    <ul if.bind="subMenu.subNavSettings.subSubNav" class="dropdown-menu">
                                        <li repeat.for="lowestSubMenu of subMenu.subNavSettings.subSubNav" class="dropdown-submenu">
                                            <a href.bind="lowestSubMenu.href"> <span class="glyphicon glyphicon-${ lowestSubMenu.subSubNavSettings.icon }"></span> ${lowestSubMenu.title}</a>
                                        </li>
                                    </ul>                        
                                </li>
                            </ul>
                        </li> [ALL THE ANCHORS HERE OR A DIVIDER.. HOW DO I DO A TERNARY TO CHECK ON EACH REPEAT FOR A DIVIDER VALUE IN THE SETTINGS ARRAY. 

                    </ul>
                </li>
            </ul>

Here is an exert from the route map that the navmenu reads from:

{
            route: "clients",
            name: "clients",
            moduleId: PLATFORM.moduleName("../components/clients/clientList/clientList"),
            title: "Clients",
            nav: true,
            settings: {
                nav: [
                    {
                        href: "#clients/clientsList",
                        title: "Client List",
                        navSettings: {
                            icon: "list",
                            roles: ["Employee", "Admin"],
                        }
                    },
                    {
                        navSettings: {
                            roles: ["Employee", "Admin"],
                            divider: true,  // HERE IS MY DIVIDER
                        }
                    },
                    {
                        href: "#clients/Create",
                        title: "Create Client",
                        navSettings: {
                            icon: "user",
                            roles: ["Employee", "Admin"],
                        }
                    }
                ],
                icon: "user",
                auth: true,
                roles: ["Employee", "Admin"],
                pos: "left"
            }
        },

The problem is that the <li></li> does a repeat and I need to check in that repeat - li to see if "navSettings has an entry divider: true and if so not show the link (menu item) but instead show a line divider.

How do I discard the anchors and instead show a list line with class "divider". Whats throwing me is the fact that the li has a repeat.for and I need to either show everything between the <li></li>tags or instead show a divider.

I need to check on the line:

<li repeat.for="menu of route.settings.nav" class="dropdown-submenu">

and change the class from "dropdown-submenu" to "divider" while at the same time not show any of the anchors <a></a> by doing similar check (if.bind I am guessing) for divider..

Hope you can help..


回答1:


In the <li> use class="${menu.divider ? 'divider' : 'dropdown-submenu'}".

Use if.bind on menu.divider for the elements inside the <li>.

<li repeat.for="menu of route.settings.nav" class="${menu.divider ? 'divider' : 'dropdown-submenu'}">
    <a if.bind="!menu.divider" href.bind="lowestSubMenu.href"> <span class="glyphicon glyphicon-${ lowestSubMenu.subSubNavSettings.icon }"></span> ${lowestSubMenu.title}</a>
    <div if.bind="menu.divider" class="divider"></div>
</li>


来源:https://stackoverflow.com/questions/47868920/aurelia-a-way-to-add-a-divider-into-a-multi-level-drop-down-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!