本文主要是介绍rails 集成wangEditor编辑器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
rails集成
class JxcatFormBuilder < SimpleForm::FormBuilderdelegate :content_tag, :link_to, :icon, :safe_join, :raw, to: :@templatedef wangeditor_picker(attribute_name, options = {})input(attribute_name, options) docontent_tag :div, class: 'wangeditor-picker', data: options[:data] dovalue = object.send(attribute_name)input_tag = content_tag :div,raw(value),id: 'editor',class: 'wangeditor-picker-box'hidden = hidden_field attribute_name, class: 'wangeditor-picker-field', id: 'editor_field', value: value[input_tag, hidden].join&.html_safeendendend
end
js集成
if ($('#editor').length > 0) {const wangEditor = window.wangEditorconst editor = new wangEditor(document.getElementById('editor'))editor.config.zIndex = 50editor.config.customUpload = trueeditor.config.uploadImgServer = '/api/detail_uploads'// $('#editor_field').val(html)editor.create()editor.onchange = () => {$('#editor_field').val(editor.$txt.html())}}
使用:
<%= f.wangeditor_picker :content, label: "内容"%>
这篇关于rails 集成wangEditor编辑器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!