簡體   English   中英

在helpers方法欄上添加selected-select

[英]add chosen-select in the helpers method rails

我正在嘗試使用chosen-select作為選項。 我沒有使用任何表單字段或表單生成器。

我正在通過輔助方法

 def options_for_part_child(part_child)
 attr_name = attribute_name(part_child.parent, part_child, 'id')
 html = "<div class='col-sm-2 uno_part_wrapper'>"
 html += "<select class='form-control switcher chosen-select'
                name='#{attr_name}'
                data-part-name='#{part_child.name}'
                data-part-id='#{part_child.id}'
                data-part-type='#{part_child.display_type}'
                data-parent-part-id='#{part_child.parent.id unless part_child.root?}'>"
 part_child.options.each do |o|
 html += "<option value='#{o.id}'
                data-option-part-id='#{part_child.id}'
                data-option-name='#{o.name}'
                data-option-id='#{o.id}'
                data-option-disables='#{o.disables.present? ? o.disables.map(&:disable_element_id) : nil}'
                data-option-enables='#{o.enables.present? ? o.enables.map(&:enable_element_id) : nil}'
                #{o.is_default? ? 'selected' : ''}>#{o.name}
          </option>"
 end
 html += "</select>"
 html += "</div>"
 html.html_safe
 end

這就是我的選擇方式。

有人可以幫我把它與chosen-select jquery插件一起使用。

您可以在腳本標記中的頁面上進行初始化。

<script type="text/javascript">
  $(document).ready(function(){  
    $('select.chosen-select').chosen()
  });
</script>

如果將其用於多個頁面,則最好在自定義js文件中使用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM