Ace 编辑器不格式化编辑器 div 中的数据 [英] Ace editor doesn't format the data inside the editor div
问题描述
我在编辑器 div 中嵌入了一些 JSON
数据.
I have embedded some JSON
data inside the editor div.
如下:http://jsfiddle.net/P3TwV/11/
但是如小提琴所示,JSON 没有被格式化.它只是将数据放在一行中.
But as shown in the fiddle, the JSON is not being formatted. It simply put the data in one line.
我想要的数据,我在没有任何空格的单行中输入,应该自动格式化并正确缩进,根据指定的类型作为这里的 JSON,并且编辑器内的所有对象的折叠和展开都应该启用.
i want the data, that i inputed in single line without any spaces, should get automatically formatted with proper indenting, according to the specified type as here JSON and all the folding and unfolding of the objects inside the editor should get enable.
我该如何处理?
任何答案都会在这里帮助我.谢谢.
Any answer will help me here. Thank you.
推荐答案
Ace 不支持格式化代码,你可以使用 beautify.js 或浏览器内置的 json 格式化程序
Ace doesn't support formatting the code, you can either use beautify.js or browsers built-in json formatter
var val = editor.session.getValue()
var o = JSON.parse(val) // may throw if json is malformed
val = JSON.stringify(o, null, 4) // 4 is the indent size
editor.session.setValue(val)
这篇关于Ace 编辑器不格式化编辑器 div 中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!