【问题标题】:add chosen-select in the helpers method rails在辅助方法 rails 中添加选择选择
【发布时间】:2015-04-14 11:09:46
【问题描述】:

我正在尝试使用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 插件。

【问题讨论】:

    标签: jquery ruby-on-rails jquery-chosen


    【解决方案1】:

    您可以在脚本标签中对页面进行初始化。

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

    如果在多个页面上使用它,那么最好在您的自定义 js 文件中使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多