【发布时间】:2018-01-09 10:08:37
【问题描述】:
我将我的 html 代码以 json 格式保存到 sql 数据库中
const content = this.state.editorState.getCurrentContent();
const raw = JSON.stringify(convertToRaw(content))
原始是
{"entityMap":{},"blocks":[{"key":"4bk88","text":"ridee","type":"unstyled","depth":0,"inlineStyleRanges" :[],"entityRanges":[],"data":{}}]}
但是,当我在服务器中使用 XMLHTTPRequest 发送它时,它会将 req.body 更改为
post.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
这就是它的保存方式
{"{\"entityMap\":{},\"blocks\":[{\"key\":\"Some Text\",\"text\":\"ridee\",\" type\":\"unstyled\",\"depth\":0,\"inlineStyleRanges\":":[""]}
所以在我收到后它不会作为预期的对象返回
const raw = JSON.parse(req.response.htmlcode)
const contentState = convertFromRaw(raw);
{"entityMap":{},"blocks":[{"key":"Some Text","text":"ridee","type":"unstyled","depth":0,"inlineStyleRanges “: :
我按预期得到了这个,但是 convertFromRaw 给出了这个错误
无法将 undefined 或 null 转换为对象
Object.keys(entityMap).forEach(function (storageKey)
提前致谢!
【问题讨论】:
标签: javascript reactjs html-editor draftjs