将内容插入wp_editor tinyMCE不向编辑器添加换行符

时间:2015-02-18 16:20:55

标签: ajax wordpress wordpress-plugin tinymce wp-editor

我通过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

0 个答案:

没有答案