如何用.select2大胆标题?

时间:2015-12-08 20:01:28

标签: ruby-on-rails ruby jquery-select2 ui-select2 select2-rails

如何使用ruby添加粗体标题(又名optgroup)select2

  <%= @challenge.select(:name, [[], ['optgroup label: Mind'], ['Write a Book'], ['Paint a Picture'], ['optgroup label: Body'], ['Run a 5K'], ['Lose 10 Pounds']]) %>

  $('select').select2({
    placeholder: "Enter Challenge",
    theme: "bootstrap",
    allowClear: false,
    tags: true,
    multiple: false,
  });

我很难将这里提供的答案翻译成红宝石解决方案:Select2 - How to insert a bolded headline?

1 个答案:

答案 0 :(得分:1)

您是否尝试过:grouped_collection_select

http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/grouped_collection_select

更新了示例:

控制器:

@collection = [['Mind', ['Write a Book', 'Paint a Picture']], ['Body', ['Run a 5K', 'Lose 10 Pounds']]]

查看:

<%= @challenge.grouped_collection_select(:name, @collection, :last, :first, :to_s, :to_s, include_blank: true) %>

显然我没有确切的源代码,但这应该可行。