Bootstrap侧边栏下拉菜单

时间:2014-11-06 20:50:10

标签: jquery css twitter-bootstrap zend-framework

是否有基于引导程序的侧边栏导航面板并带有下拉菜单?我看了很多,找不到一个。这是我当前的代码(它创建一个子菜单,但下拉菜单不起作用):

            <div class="col-sm-3 col-md-2 sidebar">    
               <ul class="nav nav-sidebar">     
                    <?php foreach ($this->container as $page): ?>
                        <?php if( ! $page->isVisible() || !$this->navigation()->accept($page)) continue; ?>
                            <?php if(isset($page->pages) && count($page->pages)):?>
                                <li class="dropdown open">
                            <a href="<?php echo $page->getHref() ?>" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
                              <?php echo $this->translate($page->getLabel()) ?>
                            </a>
                                <ul class="dropdown-menu" role="menu">
                                    <?php foreach($page->pages as $subpage):?>
                                    <li>
                                        <a href="<?php echo $subpage->getHref();?>">
                                            <?php echo $this->translate($subpage->getLabel());?>
                                        </a>
                                        <?php if(isset($subpage->pages) && count($subpage->pages)):?>
                                            <ul class="dropdown-menu" role="menu">
                                            <?php foreach($subpage->pages as $innerpage):?>
                                                <li>
                                                    <a href="<?php echo $innerpage->getHref();?>">
                                                        <?php echo $this->translate($innerpage->getLabel());?>
                                                    </a>
                                                </li>       
                                            <?php endforeach;?>
                                            </ul>       
                                        <?php endif;?>
                                    </li>
                                    <?php endforeach;?>
                                </ul>
                                <?php else:?>
                                    <li>
                            <a href="<?php echo $page->getHref() ?>">
                              <?php echo $this->translate($page->getLabel()) ?>
                            </a>
                            <?php endif;?>                
                      </li>
                       <?php endforeach ?>
                  </ul>
              </div>

2 个答案:

答案 0 :(得分:0)

几周前,我在同样的事情上挣扎过。我发现你的代码存在同样的问题,所以我编辑了你的代码,见下文。

试试这个:

    <div class="col-sm-3 col-md-2 sidebar">    
           <ul class="nav nav-sidebar">     
                <?php foreach ($this->container as $page): ?>
                    <?php if( ! $page->isVisible() || !$this->navigation()->accept($page)) continue; ?>
                        <?php if(isset($page->pages) && count($page->pages)):?>
                            <li class="dropdown open">
                        <a href="<?php echo $page->getHref() ?>" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
                          <?php echo $this->translate($page->getLabel()) ?>
                        </a>
                            <ul class="dropdown-menu" role="menu">
                                <?php foreach($page->pages as $subpage):?>
                                   <li class="dropdown">
                                    <a href="<?php echo $subpage->getHref();?>">
                                        <?php echo $this->translate($subpage->getLabel());?>
                                    </a>
                                    <?php if(isset($subpage->pages) && count($subpage->pages)):?>
                                        <ul class="dropdown-menu" role="menu">
                                        <?php foreach($subpage->pages as $innerpage):?>
                                            <li class="dropdown">
                                                <a href="<?php echo $innerpage->getHref();?>">
                                                    <?php echo $this->translate($innerpage->getLabel());?>
                                                </a>
                                            </li>       
                                        <?php endforeach;?>
                                        </ul>       
                                    <?php endif;?>
                                </li>
                                <?php endforeach;?>
                            </ul>
                            <?php else:?>
                                <li>
                        <a href="<?php echo $page->getHref() ?>">
                          <?php echo $this->translate($page->getLabel()) ?>
                        </a>
                        <?php endif;?>                
                  </li>
                   <?php endforeach ?>
              </ul>
          </div>

答案 1 :(得分:0)

这个怎么样:

<div class="container">  
<div class="row">
    <div class="col-sm-2">
        <nav class="nav-sidebar">
            <ul class="nav">    
                <?php foreach ($this->container as $page): ?>
                    <?php if( ! $page->isVisible() || !$this->navigation()->accept($page)) continue; ?>
                        <?php if(isset($page->pages) && count($page->pages)):?>
                            <li class="dropdown open">
                        <a href="<?php echo $page->getHref() ?>" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
                          <?php echo $this->translate($page->getLabel()) ?>
                        </a>
                            <ul class="dropdown-menu" role="menu">
                                <?php foreach($page->pages as $subpage):?>
                                <li class="dropdown">
                                    <a href="<?php echo $subpage->getHref();?>">
                                        <?php echo $this->translate($subpage->getLabel());?>
                                    </a>
                                    <?php if(isset($subpage->pages) && count($subpage->pages)):?>
                                        <ul class="dropdown-menu" role="menu">
                                        <?php foreach($subpage->pages as $innerpage):?>
                                            <li class="dropdown">
                                                <a href="<?php echo $innerpage->getHref();?>">
                                                    <?php echo $this->translate($innerpage->getLabel());?>
                                                </a>
                                            </li>       
                                        <?php endforeach;?>
                                        </ul>       
                                    <?php endif;?>
                                </li>
                                <?php endforeach;?>
                            </ul>
                            <?php else:?>
                                <li>
                        <a href="<?php echo $page->getHref() ?>">
                          <?php echo $this->translate($page->getLabel()) ?>
                        </a>
                        <?php endif;?>                
                  </li>
                   <?php endforeach ?>
              </ul>
              </nav>
          </div>
    </div>