jQuery 选择菜单与 Rails grouped_collection_select

发布于 2024-12-20 14:10:16 字数 957 浏览 0 评论 0原文

我一直在尝试 jQuery-ui Selectmenu,但无法让它与 grouped_collection_select 一起使用。当我将类设置为“selectmenu”时,Selectmenu 与基本选择一起使用,我已设置 jQuery-ui 来查找它。基本上,我正在努力将类添加到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 的类。我检查了源代码,没有使用 :class=> 添加类在grouped_collection_select中。

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

I have been playing around with the jQuery-ui Selectmenu, but haven't been able to get it to work with the grouped_collection_select. The Selectmenu works with the basic select when I set the class to "selectmenu," which I have set the jQuery-ui to look for. Basically, I'm struggling to add Class to grouped_collection_select.

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

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

I was able to add the class using $('#user_state_id).addClass('selectmenu') in my coffeescript. However, this seemed to cause my dynamic menu from being able to update the options for my State select menu.

Any thoughts on what I'm missing here? Is there a better way to set the class for grouped_collection_select. I've checked the source code and the class is not being added using :class=> in grouped_collection_select.

The selectmenu:
http://jquery-ui.googlecode.com/svn/branches/labs/selectmenu/index.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风轻花落早 2024-12-27 14:10:16

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 =>; 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]">...

grouped_collection_select takes nine arguments. If you are passing object in with the f it only takes eight arguments.

The last argument is html_options, where you need to place the class. This will get you the class on the select form field element but not optgroup or option elements.

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

Without the :include_blank => true it would look like this:

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

Which should get you:

<select class="selectmenu" id="object_state_id" name="object[state_id]">...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文