ACE๋ ์ด๊ธฐ ๊ฐ์ ์ค์ ํ๊ณ ๋ฉ ํจ๊ณผ๊ฐ ์์ผ๋ฉฐ ํฌ๋งทํ ์ ์์ต๋๋ค.
๋ฒ์ : "react-ace": "^5.8.0"
this.state.SimBody = {"id":123456,"name":"ACE","age":111};
<AceEditor
readOnly={fale}
onChange={this.handleGetBody}
width="100%"
height="500px"
mode="json"
theme="github"
name="aceCodeEditor"
onLoad={this.onLoad}
fontSize={14}
showPrintMargin={true}
showGutter={true}
highlightActiveLine={true}
value={this.state.modelBody}
editorProps={{
$blockScrolling: true,
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
enableSnippets: true
}}
setOptions={{
showLineNumbers: true,
tabSize: 2
}}/>
๋ฆฌ์กํธ ์์ด์ค
์งํ ์ํฉ: #
์ด๋ ๊ฒ ํ์๋ฉ๋๋ค
๋๋ ์ด๋ ๊ฒ ๊ธฐ๋ํ๋ค
@ Bobcui001 ํธ์ง๊ธฐ๋ ์ค๋ช
๋๋ก json ํ์์ ์๋์ผ๋ก ์ง์ ํ์ง ์์ต๋๋ค. ๊ทธ๋ฌ๋ ํด๋น ํ์์ผ๋ก ๊ฐ์ ธ์ค๋ ค๋ฉด JSON.stringify(this.state.modelBody, null, '\t');
์ค๋ช
ํ๋ ๋๋ก json์ ๊ฝค ์ธ์ํด์ผ ํฉ๋๋ค.
์๋
ํ์ธ์, JSON.stringify(this.state.modelBody, null, '\t')๊ฐ ์๋ํ์ง ์์ต๋๋ค.
๋ด๊ฐ ์
๋ ฅํ ๋
๋ฐ setValue( JSON.stringify(this.state.modelBody, null, '\t'))๋ ๋ค์์ ๋ฐํํ์ต๋๋ค.
@securingsincity
@Aaron-Lei ์๋
JSON.stringify(JSON.parse(this.state.modelBody), null, 2);
์ฌ๊ธฐ์ ์ธ ๋ฒ์งธ ๋งค๊ฐ๋ณ์๋ ์ํ๋ ๊ณต๋ฐฑ ์์ ๋๋ค.
@Aaron-Lei์ ๋์ผํ ๋ฌธ์
์ด ๋ฌธ์ ๋ ๊ฒช๊ณ ์์ต๋๋ค. ์๊ฐ์ด ์ข ๋จ์ ๋ ์กฐ์ฌํด ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
ํธ์งํ๋ค
๋ฐ๋ผ์ ๋์ผํ ๋ฌธ์์ด์์ JSON.stringify
๋ฅผ ๋ ๋ฒ ์คํํ๋ฉด ์ด๋ฐ ์ผ์ด ๋ฐ์ํฉ๋๋ค. ๊ฐ JSON.stringify
$ ์ ๋ํด $ JSON.parse
๋ฅผ ์คํํด์ผ ํฉ๋๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ถ๊ฐ ์ฌ๋์๋ฅผ ์ถ๊ฐํ ์ํ์ด ์์ต๋๋ค.
์ ๊ฒฝ์ฐ์๋ useEffect
์ ์ํ ๊ด๋ฆฌ์์ ๋ชจ๋ ๋ฌธ์์ดํํ๊ณ ์์์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@ Bobcui001 ํธ์ง๊ธฐ๋ ์ค๋ช ๋๋ก json ํ์์ ์๋์ผ๋ก ์ง์ ํ์ง ์์ต๋๋ค. ๊ทธ๋ฌ๋ ํด๋น ํ์์ผ๋ก ๊ฐ์ ธ์ค๋ ค๋ฉด
JSON.stringify(this.state.modelBody, null, '\t');
์ค๋ช ํ๋ ๋๋ก json์ ๊ฝค ์ธ์ํด์ผ ํฉ๋๋ค.