草案js。将EditorContent持久化到数据库 [英] Draft js. Persist EditorContent to database

查看:191
本文介绍了草案js。将EditorContent持久化到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 draft-js EditorContent 保留到数据库,然后读取并重新创建EditorContent对象再次。
但是 EditorContent.getPlainText()去掉富文本内容。我不知道怎么做。

I'm trying to persist draft-js's EditorContent to database then read and recreate the EditorContent object again. But EditorContent.getPlainText() strips away rich text content. I don't know how else to do it.

如何正确持久 EditorContent

推荐答案

getPlainText()方法,顾名思义,只返回纯文本而没有任何丰富的格式。您应该使用 convertToRaw()和convertFromRaw()函数序列化和反序列化编辑器的内容。

The getPlainText() method, as its name suggests, only returns the plain text without any rich formatting. You should use the convertToRaw() and convertFromRaw() functions to serialize and deserialize the contents of the editor.

如有必要,您可以这样导入:(假设您使用的是ES6)

You can import them this way if necessary: (assuming you are using ES6)

import {convertFromRaw, convertToRaw} from 'draft-js';

如果您需要导出HTML,请参阅https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2# 9260 (不确定您是否可以从HTML导入内容)

If you need to export HTML instead, see https://medium.com/@rajaraodv/how-draft-js-represents-rich-text-data-eeabb5f25cf2#9260 (not sure you can import the contents back from HTML, though)

这篇关于草案js。将EditorContent持久化到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆