我完成了 grouped_options_for_select。我想要一个提示。如果组下没有可供选择的选项,则不应有任何空格。我尝试使用以下代码。
控制器:
@grouped_options = @subjects.inject({}) do |options, product|
(options[product.subject_name] ||= []) << [product.module_name, product.subject_module_id]
options
end
看法:
<div id="subject_module_drp_div">
<%= f.select :subject_module_id, grouped_options_for_select(@grouped_options),
{:class=>"form-control select_modules",:style=>"width:100%;"} %>
</div>
我的选择选项,
语法:
紧张的
声音科学:
数学:
代数
三角
在这里,科学没有选项可供选择。所以数学紧挨着科学。科学和数学之间没有空间。在 grouped_options_for_select 中是否有任何选项可以执行此操作。以及如何提供提示值并获得已选择的选项。
微笑和谢谢。