Ace编辑器不会格式化编辑器div中的数据 [英] Ace editor doesn't format the data inside the editor div

查看:191
本文介绍了Ace编辑器不会格式化编辑器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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆