如何从数据库中填充一个nevigation栏

时间:2015-06-14 05:26:14

标签: html css twitter-bootstrap jstl

我尝试使用数据库填充动态导航栏。有维护和子标签表。

我试过这段代码但没有用:

<nav id="bb" class="navbar navbar-default">
    <div  class="container-fluid">
      <div  class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">home</a>
      </div>
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
        <ul class="nav navbar-nav">
        <c:if test="${not empty SubtabsList}">
          <c:forEach var="maintab"  items="${MaintabsList}">
            <li><a href="#">${maintab.description}</a></li>
            <ul class="dropdown-menu" role="menu">
              <c:forEach var="subtab"  items="${SubtabsList}">
                <c:if test="${subtab.maintab.maiTabId eq maintab.maiTabId}">
                  <li><a href="#">${subtab.description}</a></li>
                </c:if>
              </ul>
            </c:forEach>
          </c:forEach>
        </c:if>
      </ul>
    </div>
  </div>
</nav>

示例复制导航栏如下:我想通过数据库自动生成此导航栏。但无法包含<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a> 在适当的地方。

<!-- <nav id="bb" class="navbar navbar-default"> -->

<!--    <div  class="container-fluid"> -->
<!--     Brand and toggle get grouped for better mobile display -->

<!--      <div  class="navbar-header"> -->

<!--        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> -->
<!--         <span class="sr-only">Toggle navigation</span> -->

<!--            <span class="icon-bar"></span> -->
<!--         <span class="icon-bar"></span> -->
<!--         <span class="icon-bar"></span> -->
<!--       </button> -->

<!--         <a class="navbar-brand" href="#">Brand</a> -->

<!--     </div> -->

<!--     Collect the nav links, forms, and other content for toggling -->

<!--      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> -->

<!--        <ul class="nav navbar-nav"> -->

<!--            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li> -->

<!--                <li><a href="#">Link</a></li> -->

<!--                <li class="dropdown"> -->

<!--                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Dropdown <span class="caret"></span></a> -->

<!--                <ul class="dropdown-menu" role="menu"> -->

<!--                    <li><a href="#">Action</a></li> -->

<!--                    <li><a href="#">Another action</a></li> -->

<!--                    <li><a href="#">Something else here</a></li> -->

<!--                    <li class="divider"></li> -->

<!--                    <li><a href="#">Separated link</a></li> -->

<!--                    <li class="divider"></li> -->

<!--                    <li><a href="#">One more separated link</a></li> -->

<!--                </ul> -->

<!--            </li> -->

<!--        </ul> -->

<!--    </div>/.navbar-collapse -->

<!--        </div>/.container-fluid -->

<!-- </nav> -->

1 个答案:

答案 0 :(得分:0)

<nav id="bb" class="navbar navbar-default">

        <div class="container-fluid">


            <div class="navbar-header">

                <button type="button" class="navbar-toggle collapsed"
                    data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span> <span
                        class="icon-bar"></span> <span class="icon-bar"></span> <span
                        class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">home</a>
            </div>



            <div class="collapse navbar-collapse"
                id="bs-example-navbar-collapse-1">

                <ul class="nav navbar-nav">
                    <c:if test="${not empty SubtabsList}">
                        <c:forEach var="maintab" items="${MaintabsList}">
                            <li class="dropdown"><a href="#" class="dropdown-toggle"
                                data-toggle="dropdown" role="button" aria-expanded="false">${maintab.description}
                                    <span class="caret"></span>
                            </a>

                                <ul class="dropdown-menu" role="menu">
                                    <c:forEach var="subtab" items="${SubtabsList}">

                                        <c:if test="${subtab.maintab.maiTabId == maintab.maiTabId}">


                                            <li><a href="${subtab.ref}">${subtab.description}</a></li>



                                        </c:if>



                                    </c:forEach>
                                </ul></li>


                        </c:forEach>

                    </c:if>
                </ul>
            </div>
        </div>
    </nav>