How to Bold Headline With .select2?



如何使用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,
  });

我很难将这里提供的答案翻译成ruby解决方案:Select2-如何插入粗体标题?

您尝试过: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) %>

很明显,我没有你确切的源代码,但这应该可以工作。

相关内容

  • 没有找到相关文章

最新更新