在 KeystoneJS 中删除 down/Sub-menus

Drop down/Sub-menus in KeystoneJS

我目前正在开发一个网站。作为要求的一部分,我需要包括一些主菜单项中的下拉 menu/sub 菜单。我可以使用 KeystoneJS 创建主菜单项,但我似乎找不到有关如何实现子菜单项的教程。我该怎么办?

你的问题有点不清楚,但我假设你是在谈论更新你在 运行 生成器之后获得的导航栏,而不是关于管理员 UI 本身?

如果是这样,这将取决于您使用的模板引擎。我自己用 handlebars 模板引擎完成了这个。我只是添加了一个locals.subsection,类似于locals.section

然后我将 routes/middleware 更新为如下所示:

locals.navLinks = [
    { label: 'Home',        key: 'home',        href: '/' },
    { label: 'About Us',        key: 'about',       pages: [
        { label: 'What We Do',      subkey: 'whatwedo', href: "/whatwedo" },
        { label: 'Our Journey',     subkey: 'journey',      href: "/journey"    }
        ] },
    { label: 'Blog',        key: 'blog',        href: '/blog' }
];

在上面的示例中,"About Us" 菜单项将是一个下拉菜单,而其他两个则不是。然后在您个人页面的路由上,您需要指定 section,如果您希望它成为下拉列表,还需要指定 subsection。在上面的例子中,whatwedo 路由有 locals.section: aboutlocals.subsection: whatwedo.

然后您需要更新您的默认布局。对我来说,它是用车把写的,所以看起来像这样:

{{# each navLinks}}
    {{#if href}}    
        <li {{#ifeq ../../section key}}class="active"{{/ifeq}}>
            <a href="{{ href }}">{{ label }}</a>
        </li>
    {{else}}
        <li class="dropdown{{#ifeq ../../section key}} active{{/ifeq}}">
            <a href="#" class="dropdown toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ label }} <span class="caret"></span></a>
            <ul class="dropdown-menu">
                {{#each pages}}
                    <li {{#ifeq ../../../subsection subkey}}class="active"{{/ifeq}}>
                        <a href="{{ href }}">{{ label }}</a>
                    </li>
                {{/each}}
            </ul>
        </li>
    {{/if}}
{{/each}}

我知道您可能使用的是玉而不是车把,但希望您能够 'translate' 此代码。

如果我误解了你的问题,我深表歉意。希望这可以帮助。