React-ace: ACE๋Š” ์ดˆ๊ธฐ ๊ฐ’์„ ์„ค์ •ํ•˜๊ณ  ๋žฉ ํšจ๊ณผ๊ฐ€ ์—†์œผ๋ฉฐ ํฌ๋งทํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2017๋…„ 12์›” 25์ผ  ยท  5์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: securingsincity/react-ace

๋ฌธ์ œ

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
                    }}/>

์ฐธ๊ณ ๋ฌธํ—Œ

๋ฆฌ์•กํŠธ ์—์ด์Šค
์ง„ํ–‰ ์ƒํ™ฉ: #
์ด๋ ‡๊ฒŒ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค
image
๋‚˜๋Š” ์ด๋ ‡๊ฒŒ ๊ธฐ๋Œ€ํ•œ๋‹ค
image

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

@ Bobcui001 ํŽธ์ง‘๊ธฐ๋Š” ์„ค๋ช…๋Œ€๋กœ json ํ˜•์‹์„ ์ž๋™์œผ๋กœ ์ง€์ •ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ํ•ด๋‹น ํ˜•์‹์œผ๋กœ ๊ฐ€์ ธ์˜ค๋ ค๋ฉด JSON.stringify(this.state.modelBody, null, '\t'); ์„ค๋ช…ํ•˜๋Š” ๋Œ€๋กœ json์„ ๊ฝค ์ธ์‡„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋ชจ๋“  5 ๋Œ“๊ธ€

@ Bobcui001 ํŽธ์ง‘๊ธฐ๋Š” ์„ค๋ช…๋Œ€๋กœ json ํ˜•์‹์„ ์ž๋™์œผ๋กœ ์ง€์ •ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ํ•ด๋‹น ํ˜•์‹์œผ๋กœ ๊ฐ€์ ธ์˜ค๋ ค๋ฉด JSON.stringify(this.state.modelBody, null, '\t'); ์„ค๋ช…ํ•˜๋Š” ๋Œ€๋กœ json์„ ๊ฝค ์ธ์‡„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์•ˆ๋…•ํ•˜์„ธ์š”, JSON.stringify(this.state.modelBody, null, '\t')๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
๋‚ด๊ฐ€ ์ž…๋ ฅํ•  ๋•Œ
image
๋ฐ setValue( JSON.stringify(this.state.modelBody, null, '\t'))๋Š” ๋‹ค์Œ์„ ๋ฐ˜ํ™˜ํ–ˆ์Šต๋‹ˆ๋‹ค.

image
@securingsincity

@Aaron-Lei ์‹œ๋„
JSON.stringify(JSON.parse(this.state.modelBody), null, 2);

์—ฌ๊ธฐ์„œ ์„ธ ๋ฒˆ์งธ ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” ์›ํ•˜๋Š” ๊ณต๋ฐฑ ์ˆ˜์ž…๋‹ˆ๋‹ค.

@Aaron-Lei์˜ ๋™์ผํ•œ ๋ฌธ์ œ

์ด ๋ฌธ์ œ๋„ ๊ฒช๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์‹œ๊ฐ„์ด ์ข€ ๋‚จ์„ ๋•Œ ์กฐ์‚ฌํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

ํŽธ์ง‘ํ•˜๋‹ค
๋”ฐ๋ผ์„œ ๋™์ผํ•œ ๋ฌธ์ž์—ด์—์„œ JSON.stringify ๋ฅผ ๋‘ ๋ฒˆ ์‹คํ–‰ํ•˜๋ฉด ์ด๋Ÿฐ ์ผ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค. ๊ฐ JSON.stringify $ ์— ๋Œ€ํ•ด $ JSON.parse ๋ฅผ ์‹คํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์ถ”๊ฐ€ ์Šฌ๋ž˜์‹œ๋ฅผ ์ถ”๊ฐ€ํ•  ์œ„ํ—˜์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ œ ๊ฒฝ์šฐ์—๋Š” useEffect ์™€ ์ƒํƒœ ๊ด€๋ฆฌ์—์„œ ๋ชจ๋‘ ๋ฌธ์ž์—ดํ™”ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰