【问题标题】:Display text in Quill editor在 Quill 编辑器中显示文本
【发布时间】:2016-10-12 08:42:08
【问题描述】:

当我尝试设置包含“\n”的文本时。它显示错误 - Uncaught SyntaxError: Unexpected token ILLEGAL in browser console

在 java 脚本控制台中,我得到如下文本。

<script type="text/javascript">
  var toolbarOptions = [
    [{ 'font': [] }],
    [{ 'size': ['small', false, 'large', 'huge'] }],  // custom dropdown
    ['bold', 'italic', 'underline', 'strike'],        // toggled buttons
    //['blockquote', 'code-block'],

    [{ 'header': 1 }, { 'header': 2 }],               // custom button values
    [{ 'list': 'ordered'}, { 'list': 'bullet' }],
    //[{ 'script': 'sub'}, { 'script': 'super' }],      // superscript/subscript
    [{ 'indent': '-1'}, { 'indent': '+1' }],          // outdent/indent
    //[{ 'direction': 'rtl' }],                         // text direction
    [{ 'color': [] }, { 'background': [] }],          // dropdown with defaults from theme

    [{ 'align': [] }],

    ['clean']                                         // remove formatting button
  ];
  var quill = new Quill('#standalone-container', {
      modules: {
      toolbar: toolbarOptions
    },
    theme: 'snow'
  });
  var quill1 = new Quill('#standalone-container1', {
      modules: {
      toolbar: toolbarOptions
    },
    theme: 'snow'
  });

  $(".tacti_note_txt").click(function(){
    $("#order_video_01").get(0).pause();
  })

  $(".tech_note_txt").click(function(){
    $("#order_video_02").get(0).pause();
  })

  $(document).ready(function(){

    // my element which display errors
    var technical_notes = '<%= raw @review.technical_notes %>';
    quill.setText(technical_notes);

    var tactical_notes = '<%= @review.tactical_notes.to_s %>';
    quill1.setText(tactical_notes);

  });
</script>

我想在编辑器中显示如下文本:

  'Rails
   and
   quill
   editor
   ;

【问题讨论】:

  • 请显示浏览器的var technical_notes...
  • \n 符号可能会将该行分成多行。尝试使用`` 字符串而不是'' 字符串
  • @Dimava,我在这里遇到错误 -> var Technical_notes = '';
  • 这里的问题是编辑器需要像 "uhgfjgfjvj\r\nghjghjghjhgj\r\nghj\r\nghj\r\nhg\r\njghj\r\n" 这样的文本。我的数据库也保存了相同的。但是在页面上显示它认为输入的文本而不是“\n”,这就是问题

标签: javascript ruby-on-rails ruby-on-rails-4 quill


【解决方案1】:

这只是一个猜测,但您可能需要使用转义字符\ 所以试试"\\n"

编辑:

使用"&lt;br/&gt;"标签代替"\n"

【讨论】:

  • 试试“
    ”标签而不是\n?

  • 标签替换文本不是好的选择,因为我的文本是动态的
【解决方案2】:

ActiveSupport::JSON.encode(my_string) - 为我工作。

因为它使用 \n 和 \t 保存我的字符串,所以 quill 编辑器以正确的格式显示它:

 'Rails
   and
   quill
   editor
   ;

【讨论】:

    猜你喜欢
    • 2022-06-17
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多