如何获得CKEditor值?

时间:2014-11-19 13:35:57

标签: jquery ruby-on-rails ajax ckeditor

我在视图中有这个输入字段:

<div class="treatment-service">
  <%= f.input :service_id, as: :select, collection: current_partner.services.pluck(:name, :id), :label => "Serviciu" %>
</div>
<%= f.input :description, :as => :ckeditor, :input_html => { :ckeditor => {:toolbar => 'Pure'}}%>

和我的treatments.js文件中的这个函数,我根据下拉列表中选择的值自动完成详细信息。

var serviceDetails = function (){
  $('.treatment-service').change(function(){
      var service_id = $(this).find('select').val();
      debugger
      $.ajax({
        type: 'get',
        url: "/treatment_services/"+service_id,
        dataType: 'json',
        success: function(data){
          debugger
        $('.treatment-service').closest('div').next().find('input').val(data.price)
        $('.treatment-service').closest('div').next().next().find('input').val(data.unit)
        }
      })
    });
}

控制器:

  def service_details
    render json: current_partner.services.find(params[:service_id])
  end

路线:

get '/treatment_services/:service_id' => 'treatments#service_details'

但是如何从ckeditor字段中获取实例值? 谢谢!

1 个答案:

答案 0 :(得分:1)

不确定我完全理解,但您可以通过以下方式获取CKEditor实例的值:

CKEDITOR.instances['div_id'].getData() // the div id without a #