2 回答
TA贡献1858条经验 获得超8个赞
列出每一行,然后map(),join()就\n可以了
this.setState({ body: value.blocks.map(x => x.text).join("\n") });
import React from "react";
import Body from "./Body";
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
body: ""
};
}
changeBodyHandler = value => {
this.setState({ body: value.blocks.map(x => x.text).join("\n") });
};
render() {
console.log(this.state.body);
return (
<div>
<Body
label="Body"
name="body"
value={this.state.body}
onChange={this.changeBodyHandler}
/>
</div>
);
}
}
export default App;
TA贡献1876条经验 获得超6个赞
如果您想要像编辑器中那样使用断线,请<p>在连接时添加标签。
changeBodyHandler = value => {
let data =value.block;
let text = "";
data.map(index => {
text = text +"<p>" +index.text+"</p>";
});
this.setState({
body: text
});
};
如果您想在某个地方以相同的方式显示数据,请使用dangerouslySetInnerHTML
<div dangerouslySetInnerHTML={{__html: this.state.body}} />
- 2 回答
- 0 关注
- 81 浏览
添加回答
举报