刷新后如何保留多个 select_tag 的选定值?
<%= select_tag(:cars, options_for_select( [['bmw', 50000], ['audi', 55000], ['fiat', 20000], 0 ), :multiple => true, :title=> "All Makes", :class => "selectpicker input-small" ) %>
刷新后如何保留多个 select_tag 的选定值?
<%= select_tag(:cars, options_for_select( [['bmw', 50000], ['audi', 55000], ['fiat', 20000], 0 ), :multiple => true, :title=> "All Makes", :class => "selectpicker input-small" ) %>
您可以将选定值列表作为第二个选项传递给options_for_select
:
<%= select_tag(:cars,
options_for_select([['bmw', 50000],
['audi', 55000],
['fiat', 20000]],
[55000, 50000]),
:multiple => true, :title=> "All Makes",
:class => "selectpicker input-small" ) %>
在这种情况下bmw
,audi
将选择选项。
更多信息请参见此处的 API 参考。