【问题标题】:jQuery Selectmenu with Rails grouped_collection_select带有 Rails 的 jQuery 选择菜单 grouped_collection_select
【发布时间】:2012-01-17 13:50:10
【问题描述】:

我一直在使用 jQuery-ui 选择菜单,但无法让它与 grouped_collection_select 一起使用。当我将类设置为“selectmenu”时,Selectmenu 与基本选择一起使用,我已将 jQuery-ui 设置为要查找的。基本上,我正在努力将 Class 添加到grouped_collection_select

我尝试过: <%= f.grouped_collection_select(:state_id, Country.order(:id), :categories, :name, :id, :name, {:include_blank=>true, :class=>"selectmenu"})%>

<%= f.grouped_collection_select(:state_id, Country.order(:id), :categories, :name, :id, :name, :class=>"selectmenu")%>

我能够在我的咖啡脚本中使用 $('#user_state_id).addClass('selectmenu') 添加类。但是,这似乎导致我的动态菜单无法更新状态选择菜单的选项。

对我在这里缺少的东西有什么想法吗?有没有更好的方法来设置 grouped_collection_select 的类。我检查了源代码,并没有在grouped_collection_select 中使用 :class=> 添加该类。

选择菜单: http://jquery-ui.googlecode.com/svn/branches/labs/selectmenu/index.html

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 jquery-ui select-menu


    【解决方案1】:

    grouped_collection_select 接受九个参数。如果您使用f 传递对象,则只需要八个参数。

    最后一个参数是html_options,这里需要放置class。这将在select 表单字段元素上为您提供class,而不是optgroupoption 元素。

    <%= f.grouped_collection_select(:state_id, Country.order(:id), :categories, :name, :id, :name, { :include_blank => true }, { :class=> "selectmenu" }) %>
    

    没有:include_blank =&gt; true,它看起来像这样:

    <%= f.grouped_collection_select(:state_id, Country.order(:id), :categories, :name, :id, :name, {}, { :class=> "selectmenu" }) %>
    

    你应该得到哪个:

    <select class="selectmenu" id="object_state_id" name="object[state_id]">...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多