CKEDITOR setData with HTML string returns SyntaxError: Invalid or unexpected token

CKEDITOR setData with HTML string returns SyntaxError: Invalid or unexpected token

我正在尝试将来自数据库的 HTML 数据显示到我的 CKEDITOR 中,问题是当我尝试使用 setData 插入 html 时出现以下错误:

Uncaught SyntaxError: Invalid or unexpected token

HTML:

<label for="descricao">Descrição</label>
<textarea id="description" name="description" class="form-control descricao_anunciante" placeholder="(quem és, o que fazes ou o que representas, temas e tipos de eventos)"></textarea>
<script>
  $(document).ready(function() {
    CKEDITOR.replace('description', {
      customConfig: './js/wysiwygconfig.js'
    });
    CKEDITOR.instances["description"].setData("{!!  $evento->description !!}");
  });
</script>

但如果尝试手动插入数据,它会起作用:

CKEDITOR.instances["description"].setData("<p> Hello World </p>");

来自数据库的数据:

<p>N TEM</p>
<script>
  $(document).ready(function() {
    CKEDITOR.replace('description', {
      customConfig: './js/wysiwygconfig.js'
    });
    CKEDITOR.instances["description"].setData("{{  $evento->description }}");
  });
</script>

Or
instead of CKEDITOR.instances["description"].setData("{{  $evento->description }}"); 
you can use
<textarea id="description" name="description" class="form-control descricao_anunciante" placeholder="(quem és, o que fazes ou o que representas, temas e tipos de eventos)">
   {{  $evento->description }}
</textarea>

这会有所帮助,因为“{{ }}”- 这个 return 字符串具有 htmlentities 功能。

我也遇到了这个错误,因为如果你检查代码,你会发现它给出了错误,因为 html 进入第二行,所以它给出了语法错误,你只能通过以下方式设置数据在 textarea 中设置值。

<textarea id="description" name="description" class="form-control descricao_anunciante" placeholder="(quem és, o que fazes ou o que representas, temas e tipos de eventos)"><?= $evento->description ?></textarea>