twitter-bootstrap yii2 导航小部件子菜单类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30177703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 22:39:25  来源:igfitidea点击:

yii2 nav widget submenu class

csstwitter-bootstrapthemesyii2nav

提问by nicky

I am using the adminLTE theme for bootstrap and it uses treeview-menuclass in order to operate the submenu.

我正在使用 adminLTE 主题进行引导,它使用treeview-menu类来操作子菜单。

<?=Nav::widget([
            'options' => ['class' => 'sidebar-menu treeview'],
            'items' => [

                ['label' => 'Menu 1', 'url' => ['/a/index']],
                ['label' => 'Menu 2', 'url' => ['/custom-perks/index']],
                ['label' => 'Submenu',  'items' => [
                    ['label' => 'Action', 'url' => '#'],
                    ['label' => 'Another action', 'url' => '#'],
                    ['label' => 'Something else here', 'url' => '#'],
                    ],
                ],
            ],
        ]);
        ?>

I tried using: ['label' => 'Submenu', 'options' => ['class' => 'treeview-menu'], 'items' =>..

我尝试使用: ['label' => 'Submenu', 'options' => ['class' => 'treeview-menu'], 'items' =>..

Which obviously does not work.

这显然不起作用。

I noticed that Menu::widget has a submenuTemplatebut when I used that it stopped pickup up the "active".

我注意到 Menu::widget 有一个submenuTemplate但是当我使用它时它停止了“活动”。

Is there a way I can change either the way the adminLTE call is being applied to treeview-menu (tried changing it in app.js to dropdown-menu but that didn't help) or re-assign the UL submenu class without going into the vendor code?

有没有一种方法可以更改 adminLTE 调用应用于 treeview-menu 的方式(尝试在 app.js 中将其更改为下拉菜单,但没有帮助)或重新分配 UL 子菜单类而不进入供应商代码?

Line 65: \yii\bootstrap\Dropdown - function init()

第 65 行:\yii\bootstrap\Dropdown - 函数 init()

回答by nicky

Ok so I have found a work around - use the Menu widget instead and enable the activateParents flag:

好的,所以我找到了一个解决方法 - 改用 Menu 小部件并启用 activateParents 标志:

<?=\yii\widgets\Menu::widget([
'options' => ['class' => 'sidebar-menu treeview'],
'items' => [

    ['label' => 'Menu 1', 'url' => ['/a/index']],
    ['label' => 'Menu 2', 'url' => ['/link2/index']],
    ['label' => 'Submenu',  
        'url' => ['#'],
        'template' => '<a href="{url}" >{label}<i class="fa fa-angle-left pull-right"></i></a>',
        'items' => [
            ['label' => 'Action', 'url' => '#'],
            ['label' => 'Another action', 'url' => '#'],
            ['label' => 'Something else here', 'url' => '#'],
        ],
    ],
],
'submenuTemplate' => "\n<ul class='treeview-menu'>\n{items}\n</ul>\n",
'encodeLabels' => false, //allows you to use html in labels
'activateParents' => true,   ]);  ?>

Hopefully this helps others as well!

希望这也能帮助其他人!