0

我通过 ajax 响应将内容插入到 wp_editor 中。我从下拉列表中选择要编辑的记录,这会填充我要编辑的所有字段。这最终插入 wp_editor 内容而没有换行符。如果我手动添加换行符并保存它,它会很好地保存并正确显示内容。但是下次我去编辑那个项目时,它会在没有换行符的情况下插入到编辑器中,所以我必须再次手动添加换行符。

这是我用来创建 wp_editor 的。

$args = array(
 'textarea_rows' => 15,
 'textarea_name' => 'customEditor',
 'media_buttons' => false
);

wp_editor( '', 'customEditor', $args );

这就是我将内容从 ajax 响应插入到编辑器的方式。

tinyMCE.get( "customEditor" ).setContent(result[i].services);

插入编辑器时,它也会转义引号和单引号。我有一种感觉,这可能来自 ajax 响应 json 编码。所以认为我需要在将其发送给编辑之前对这些内容做一些事情。有谁知道解决这个问题的方法?

这是 ajax 响应在控制台中的样子

"services":"Here is a link <a href=\\\"http:\/\/www.example.com\\\">http:\/\/www.example.com<\/a>\r\n\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line\r\nthis is a new line"

像这样插入到编辑器中

Here is a link <a href="\&quot;example.com\&quot;">example.com</a>; this is a new line this is a new line this is a new line this is a new line this is a new line this is a new line this is a new line this is a new line this is a new line this is a new line this is a new line this is a new line
4

0 回答 0