在Select2保存的值中,编辑表单中的选项未显示

时间:2019-05-12 18:12:08

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

在创建新记录的情况下,带有ajax的Select2可以正常工作,但是在编辑表单的情况下,保存的选项不会显示在select2元素中。


= hidden_field_tag(:icd_procedures_ids, '', id: 'res_select', class: 'procedures-select2 procedures-ajax form-control', style: 'width: 100%;', data: { source: fetch_icd_procedures_admin_patient_prescriptions_path, selected: @prescription.icd_procedures.pluck(:id), placeholder: 'Search for procedures' })

$('.procedures-select2').each (i, e) =>
    select = $(e)
    options =
      placeholder: select.data('placeholder')
      multiple: true
    if select.hasClass('procedures-ajax')
      options.ajax =
        url: select.data('source')
        dataType: 'json'
        data: (term, page) ->
          q: term
          page: page
          per: 10
        results: (data, page) ->
          results: data.icd_procedures
          more: data.total > (page * 10)
      options.dropdownCssClass = "bigdrop"
    select.select2(options)

0 个答案:

没有答案