Yii 2 中的多级 Boostrap 菜单 [英] Multilevel Boostrap Menu in Yii 2

查看:24
本文介绍了Yii 2 中的多级 Boostrap 菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的菜单有 2 个以上的级别.看起来 Yii 2 最多只能渲染 2 个级别.例如这个:

I want my menu to have more than 2 levels. Looks like Yii 2 only renders up to 2 levels. For example this:

NavBar::begin();

echo Nav::widget([
    'options' => ['class' => 'navbar-nav navbar-right'],
    'items' => [
        [
            'label' => 'Level 1',
            'items' => [
                ['label' => 'Level 2 - 1', 'url' => '#'],
                ['label' => 'Level 2 - 2', 'url' => '#'],
                [
                    'label' => 'Level 2 - 3',
                    'items' => [
                        ['label' => 'Level 3 - 1', 'url' => '#'],
                        ['label' => 'Level 3 - 2', 'url' => '#'],
                    ],
                ],
            ]
        ],
    ],
]);

NavBar::end();

不会显示级别 3 - x 菜单项.如何向菜单添加更多级别?

will not display the Level 3 - x menu items. How do I add more levels to the menu?

推荐答案

这不是 Yii 2 的限制,而是 Boostrap 3 的限制.

This is not Yii 2 limitation, it's Boostrap 3 limitation.

以下引用自 mdo(Boostrap 3 的主要贡献者之一):

Here is quote from mdo (one of the main Boostrap 3 contributors):

我们还没有看到有人以有意义的方式使用子菜单和代码使它们正常工作所必需的开销太大.子菜单只是现在在网络上没有太多位置,尤其是移动网络.它们将在 3.0 中删除.

We haven't seen anyone using submenus in meaningful ways and the code necessary to make them work well is just too much overhead. Submenus just don't have much of a place on the web right now, especially the mobile web. They will be removed with 3.0.

它取自此处.

但是,您可以找到一些替代方法来使用更多级别.例如看看这个扩展.

However you can find some alternatives to use more levels. For example take a look this extension.

此外,此处讨论了此问题的更多详细信息和示例.

Also this question is discussed with more details and examples here.

这篇关于Yii 2 中的多级 Boostrap 菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆