0

我完成了 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 中是否有任何选项可以执行此操作。以及如何提供提示值并获得已选择的选项。
微笑和谢谢。

4

1 回答 1

0

我尝试对此问题进行更多搜索并获得解决方案。对不起,在彻底检查之前这里的问题。我的回答是,
控制器:

(options[product.subject_name] ||= []) << if product.module_name != nil then [product.module_name, product.subject_module_id] else ["Nil", :disabled => true] end   

看法:

<%= f.select :subject_module_id, grouped_options_for_select(@grouped_options, selected: @faculty_profile.subject_module_id),
        {:prompt => 'Select Module'}, {:class=>"form-control select_modules",:style=>"width:100%;"} %>  

这对我很有效。谢谢。

于 2017-01-25T10:45:25.333 回答