Bootstrap 3 中的垂直导航栏使用 UiBinder

Vertical Navbar in Bootstrap 3 using UiBinder

我的项目中有一个导航栏(GWT、GWTBootstrap3、UiBinder),我想在 UiBinder 中做成垂直的。

在HTML中很简单

<div class = "nav nav-pills nav-stacked col-sm-3"> 
    <li> <a> Home </a> </li> 
    <li> <a> Settings</a> </li> 
</div> 

但在 UiBinder 中必须可以做到同样的事情。据我了解,只能将导航栏的位置设置为 FIXED_TOP、FIXED_BOTTON 等等。

我的代码如下所示

<g:HTMLPanel>
        <g:ScrollPanel>
            <b:Container >
                 <b:Navbar position="FIXED_TOP">
                    <b:Container>
                        <b:NavbarHeader>
                            <b:NavbarBrand targetHistoryToken="{nameTokens.getHome}" ui:field="brand" text="{resources.ProductName}" />
                            <b:NavbarCollapseButton dataTarget="#navbar-collapse" />
                        </b:NavbarHeader>

                        <b:NavbarCollapse b:id="navbar-collapse">
                            <b:NavbarNav>

                                <b:ListDropDown ui:field="admindropdown">
                                    <b:AnchorButton dataToggle="DROPDOWN" text="{resources.CardHolder}" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.Employee}" targetHistoryToken="{nameTokens.getCardholderlist}" />
                                        <b:AnchorListItem text="{resources.Guest}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Vendor}" targetHistoryToken="{nameTokens.getHome}" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                                <b:ListDropDown>
                                    <b:AnchorButton dataToggle="DROPDOWN" text="{resources.User}" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Technician}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.Cloud}" targetHistoryToken="{nameTokens.getHome}" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                                <b:ListDropDown>
                                    <b:AnchorButton dataToggle="DROPDOWN" text="{resources.Configuration}" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getCustomerlist}" />
                                        <b:AnchorListItem text="{resources.Company}" targetHistoryToken="{nameTokens.getCompanylist}" />
                                        <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                        <b:AnchorListItem text="{resources.ProductNameServer}" targetHistoryToken="{nameTokens.getCloudlist}" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                            </b:NavbarNav>

                            <b:NavbarNav pull="RIGHT">

                                <b:ListDropDown >
                                    <b:AnchorButton text="{resources.SelectedLanguage}" dataToggle="DROPDOWN"  />
                                        <b:DropDownMenu >
                                            <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageDK" url="/images/DK.png" />
                                            <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageNO" url="/images/NO.png" />
                                            <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageUK" url="/images/UK.png" />
                                        </b:DropDownMenu>
                                </b:ListDropDown>

                                <b:ListDropDown ui:field="loginfield">
                                    <b:AnchorButton dataToggle="DROPDOWN" ui:field="loginname" />
                                    <b:DropDownMenu>
                                        <b:AnchorListItem text="{resources.LogOut}" ui:field="logoutitem" />
                                    </b:DropDownMenu>
                                </b:ListDropDown>

                            </b:NavbarNav>
                        </b:NavbarCollapse>
                    </b:Container>
                </b:Navbar>

                <b:Row>
                    <b:Column size="XS_12">
                        <g:SimplePanel ui:field="contentContainer" />
                    </b:Column>
                </b:Row>

            </b:Container>
        </g:ScrollPanel>
    </g:HTMLPanel>

您似乎误会了 Navbar with Navs - 您的 HTML 示例使用 nav-pills,而 UiBinder 使用 Navbarnavbarnavbar-header,等等)。据我所知(来自 Bootstrap 和 gwtbootstrap3 的文档)不可能实现垂直("stacked",正如他们在文档中所说的那样)Navbar。但是可能得到vertical/stackedNavPills:

<b:NavPills stacked="true">
   <b:AnchorListItem active="true">Item 1</b:AnchorListItem>
   <b:AnchorListItem>Item 2</b:AnchorListItem>
   <b:AnchorListItem>Item 3</b:AnchorListItem>
</b:NavPills>

有关更多示例,请参阅 the demo

我采取了另一种方法来解决这个问题,并利用了 bootstrap 中的网格系统。因此,当我们在桌面上时,我会显示一个侧面导航栏,而在 tablet/phone 上时,我会显示导航栏。它需要稍微调整一下,但这是我遇到的问题的重要部分。

这是我的 UiBinder 代码

<b:Container>

    <b:Row>

        <b:Column size="XS_12,SM_12,MD_10,LG_10" visibleOn="XS_SM">

            <b:Navbar position="FIXED_TOP">
                <b:Container>
                    <b:NavbarHeader>
                        <b:NavbarBrand targetHistoryToken="{nameTokens.getHome}"
                            ui:field="brand" text="{resources.ProductName}" />
                        <b:NavbarCollapseButton dataTarget="#navbar-collapse" />
                    </b:NavbarHeader>

                    <b:NavbarCollapse b:id="navbar-collapse">
                        <b:NavbarNav>

                            <b:ListDropDown ui:field="admindropdown">
                                <b:AnchorButton dataToggle="DROPDOWN" text="{resources.CardHolder}" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.Employee}" targetHistoryToken="{nameTokens.getCardholderlist}" />
                                    <b:AnchorListItem text="{resources.Guest}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Vendor}" targetHistoryToken="{nameTokens.getHome}" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                            <b:ListDropDown>
                                <b:AnchorButton dataToggle="DROPDOWN" text="{resources.User}" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Technician}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.Cloud}" targetHistoryToken="{nameTokens.getHome}" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                            <b:ListDropDown>
                                <b:AnchorButton dataToggle="DROPDOWN" text="{resources.Configuration}" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getCustomerlist}" />
                                    <b:AnchorListItem text="{resources.Company}" targetHistoryToken="{nameTokens.getCompanylist}" />
                                    <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                    <b:AnchorListItem text="{resources.ProductNameServer}" targetHistoryToken="{nameTokens.getCloudlist}" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                        </b:NavbarNav>

                        <b:NavbarNav pull="RIGHT">

                            <b:ListDropDown addStyleNames="{style.languageImageStyle}">
                                <b:Image url="{resources.SelectedLanguageURL}" />
                            </b:ListDropDown>

                            <b:ListDropDown>
                                <b:AnchorButton text="{resources.SelectedLanguage}" dataToggle="DROPDOWN" />
                                <b:DropDownMenu>
                                    <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageDK" url="/images/DK.png" />
                                    <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageNO" url="/images/NO.png" />
                                    <b:Image addStyleNames="btn {style.btnStyle}" ui:field="languageUK" url="/images/UK.png" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                            <b:ListDropDown ui:field="loginfield">
                                <b:AnchorButton dataToggle="DROPDOWN" ui:field="loginname" />
                                <b:DropDownMenu>
                                    <b:AnchorListItem text="{resources.LogOut}" ui:field="logoutitem" />
                                </b:DropDownMenu>
                            </b:ListDropDown>

                        </b:NavbarNav>
                    </b:NavbarCollapse>
                </b:Container>
            </b:Navbar>

        </b:Column>
    </b:Row>

    <b:Row>

        <b:Column size="MD_3,LG_3" visibleOn="MD_LG">

             <b:Panel>

            <b:PanelBody>
                <b:PanelGroup b:id="accordion">

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseOne" text="{resources.CardHolder}"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseOne" in="true" ui:field="collapseOne">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.Employee}" targetHistoryToken="{nameTokens.getCardholderlist}" />
                                <b:AnchorListItem text="{resources.Guest}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Vendor}" targetHistoryToken="{nameTokens.getHome}" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseTwo" text="{resources.User}"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseTwo" in="true">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Technician}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.Cloud}" targetHistoryToken="{nameTokens.getHome}" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>
                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseThree" text="{resources.Configuration}"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseThree" in="true">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.Customer}" targetHistoryToken="{nameTokens.getCustomerlist}" />
                                <b:AnchorListItem text="{resources.Company}" targetHistoryToken="{nameTokens.getCompanylist}" />
                                <b:AnchorListItem text="{resources.Portal}" targetHistoryToken="{nameTokens.getHome}" />
                                <b:AnchorListItem text="{resources.ProductNameServer}" targetHistoryToken="{nameTokens.getCloudlist}" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseFour" text="Sprog"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseFour" in="true">
                            <b:PanelBody>
                                <b:Image addStyleNames="btn" ui:field="languageDK2" url="/images/DK.png" />
                                <b:Image addStyleNames="btn" ui:field="languageNO2" url="/images/NO.png" />
                                <b:Image addStyleNames="btn" ui:field="languageUK2" url="/images/UK.png" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                    <b:Panel>
                        <b:PanelHeader>
                            <b:Heading size="H4">
                                <b:Anchor dataToggle="COLLAPSE" dataTarget="#collapseFive" text="Login"/>
                            </b:Heading>
                        </b:PanelHeader>
                        <b:PanelCollapse b:id="collapseFive" in="true">
                            <b:PanelBody>
                                <b:AnchorListItem text="{resources.LogOut}" ui:field="logoutitem2" />
                            </b:PanelBody>
                        </b:PanelCollapse>
                    </b:Panel>

                </b:PanelGroup>
            </b:PanelBody>
        </b:Panel>

        </b:Column>

        <b:Column size="XS_12,SM_12,MD_9,LG_9">
            <g:SimplePanel ui:field="contentContainer" />
        </b:Column>
    </b:Row>

</b:Container>