2 回答

TA貢獻(xiàn)1815條經(jīng)驗 獲得超13個贊
然后列出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貢獻(xiàn)1887條經(jīng)驗 獲得超5個贊
如果您想像在編輯器中那樣使用換行符,請在連接時添加<p>標(biāo)簽。
changeBodyHandler = value => {
let data =value.block;
let text = "";
data.map(index => {
text = text +"<p>" +index.text+"</p>";
});
this.setState({
body: text
});
};
如果您想以相同的方式顯示數(shù)據(jù),請使用dangerouslySetInnerHTML
<div dangerouslySetInnerHTML={{__html: this.state.body}} />
添加回答
舉報