【问题标题】:Simple Navigation not shown nested items using bootstrap on Rails 3在 Rails 3 上使用引导程序未显示简单导航的嵌套项
【发布时间】:2013-10-17 04:04:56
【问题描述】:

我试图嵌套我的菜单项,但它无法显示。

要点https://gist.github.com/poc7667/7019484

它应该在我的菜单中显示两个 net.item。但它没有。

我猜这个问题是由于我必须在输出 html 中做一些 css,但是怎么做呢?

primary.item :urltests, 'Network/Documentation', root_path  do |net_docs|

  net_docs.item :net, "URL Command", welcome_af_form_path do |net|        
    net.item :vvtk, "VIVOTEK", urltests_path
    net.item :sony, "SONY", sony_url_command_automation_tests_path
  end

  # net_docs.item :div, "Translate Strings", :class => 'dropdown-header'
  # net_docs.item :div, "divider" , :class => 'divider'
  # net_docs.item :trans_db, 'Firmware', translates_path
end

看这里

这是我的捆绑清单

Gems included by the bundle:
  * actionmailer (3.2.12)
  * actionpack (3.2.12)
  * activemodel (3.2.12)
  * activerecord (3.2.12)
  * activeresource (3.2.12)
  * activesupport (3.2.12)
  * arel (3.0.2)
  * atomic (1.1.14)
  * awesome_print (1.1.0)
  * bcrypt-ruby (3.1.2)
  * bootstrap-sass (2.3.2.2)
  * builder (3.0.4)
  * bundler (1.3.5)
  * cancan (1.6.10)
  * carrierwave (0.9.0)
  * celluloid (0.15.1)
  * coffee-rails (3.2.2)
  * coffee-script (2.2.0)
  * coffee-script-source (1.6.3)
  * connection_pool (1.1.0)
  * devise (3.1.1)
  * erubis (2.7.0)
  * execjs (2.0.1)
  * haml (4.0.3)
  * hike (1.2.3)
  * hirb (0.7.1)
  * hirb-unicode (0.0.5)
  * i18n (0.6.5)
  * journey (1.0.4)
  * jquery-datatables-rails (1.11.2 494f752)
  * jquery-rails (3.0.4)
  * jquery-ui-rails (4.0.4)
  * json (1.8.0)
  * mail (2.4.4)
  * mime-types (1.25)
  * mini_portile (0.5.1)
  * multi_json (1.8.0)
  * nokogiri (1.6.0)
  * orm_adapter (0.4.0)
  * pg (0.17.0)
  * polyglot (0.3.3)
  * quiet_assets (1.0.2)
  * rack (1.4.5)
  * rack-cache (1.2)
  * rack-ssl (1.3.3)
  * rack-test (0.6.2)
  * rails (3.2.12)
  * railties (3.2.12)
  * rake (10.1.0)
  * rdoc (3.12.2)
  * redis (3.0.4)
  * redis-namespace (1.3.1)
  * rest-client (1.6.7)
  * sass (3.2.10)
  * sass-rails (3.2.6)
  * sequel (3.20.0)
  * sidekiq (2.14.0)
  * simple-navigation (3.11.0)
  * simple-navigation-bootstrap (1.0.0)
  * sinatra (1.0)
  * sprockets (2.2.2)
  * sqlite3 (1.3.8)
  * taps (0.3.24)
  * thor (0.18.1)
  * thread_safe (0.1.3)
  * tilt (1.4.1)
  * timers (1.1.0)
  * tinymce-rails (4.0.2)
  * tlsmail (0.0.1)
  * treetop (1.4.15)
  * twitter-bootstrap-rails (2.2.8 40ffd56)
  * tzinfo (0.3.37)
  * uglifier (2.2.1)
  * unicode-display_width (0.1.1)
  * warden (1.2.3)
  * will_paginate (3.0.4)

输出 HTML

 <div class='navbar'>
          <div class='navbar-inner'>
            <div id='top_navi'><ul class="nav"><li id="remotefocus"><a href="/">Image</a></li><li class="active dropdown" id="urltests"><a href="/" class="dropdown-toggle active" data-target="#" data-toggle="dropdown">Network/Documentation <b class="caret"></b></a><ul class="dropdown-menu"><li class="active dropdown" id="network"><a href="/welcome/af_form" class="dropdown-toggle active" data-target="#" data-toggle="dropdown">URL Command <b class="caret"></b></a><ul class="tabs span16 dropdown-menu"><li class="active simple-navigation-active-leaf" id="vvtk"><a href="/urltests" class="active">VIVOTEK</a></li><li id="sony"><a href="/sony_url_command_automation_tests">SONY</a></li></ul></li><li id="trans_db"><a href="/translates">Firmware</a></li></ul></li><li id="translate"><a href="/">Translate String</a></li></ul></div>

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap twitter-bootstrap-3


    【解决方案1】:

    如果您需要始终呈现完整的导航树(独立于当前 URL),则需要在 expand_all 选项设置为 true 的情况下调用 render_navigation:

    render_navigation :expand_all => true, ...
    

    如果不传递此选项,simple-navigation 通常只呈现活动主导航项的子导航(取决于当前 URL)。

    【讨论】:

    • 您是否尝试过如上所述的 :expand_all 选项?
    • 哦,它没用。我可以看到 DOM 中的子菜单。但不显示在页面中
    • 如果您可以在 DOM 中看到它,但在页面上看不到,请确保它们是可见的。也许你有一个隐藏它们的 CSS 规则?
    【解决方案2】:

    @poc。 我从您的问题中了解到,您的“子菜单”有问题。
    Bootstrap 2 中有 dropdown-submenu 类,使用如下:

    <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
      ...
      <li class="dropdown-submenu">
        <a tabindex="-1" href="#">More options</a>
        <ul class="dropdown-menu">
          ...
        </ul>
      </li>
    </ul>
    

    问题是用于创建引导菜单的 gem simple-navigation-bootstrap 不会生成该类。

    我刚刚创建了另一个 gem simple_navigation_renderers 来解决这个问题并提供创建 Bootstrap 'headers' 和 'dividers' 的简单方法。也可以添加任何类型的图标(库)。而且,实际上,有两个渲染器:用于 Bootstrap 2 和用于 Bootstrap 3。;)
    尝试一下。我想它会对你有所帮助。我希望你会喜欢它。

    【讨论】:

    • 这颗宝石看起来很有前途。我应该将它添加到简单导航 wiki 吗?
    • 好的,安迪。我喜欢这个主意。如果您有任何改进的想法或建议,我会全力以赴。
    • 再说一次,@poc,从您的要点来看,很明显您已经嵌套了 dropdown-menudropdown。但这仅适用于第一级dropdown-menu。对于嵌套的dropdown-menu,在Bootstrap 2 中有一个特殊的类dropdown-submenu,正如我上面提到的。对于 nested dropdown-menu,您应该使用它 (dropdown-submenu),而不是 dropdown。在 Bootstrap 3 中没有嵌套的dropdown-menu,但你可以自己创建。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-19
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 2018-05-29
    • 1970-01-01
    相关资源
    最近更新 更多