[英]Display json object in angularjs codemirror
我有一个json对象,并想使用angularjs codemirror在codemirror上显示它,但是出现一个错误,说ui-codemirror cannot use an object or an array as a model
。 然后,我尝试使用JSON.stringify
将对象转换为字符串,该字符串在codemirror中的格式不正确。 任何人都可以帮助我弄清楚如何在Codemirror中很好地格式化我的代码? 谢谢
例如:
//inside javascript
$scope.code = {
"name": "user1",
"id": "34",
"value": [3, 5, 4]
};
$scope.editorOptions = {
lineWrapping : true,
lineNumbers: true,
mode: 'application/json',
};
//inside html
<ui-codemirror ui-codemirror-opts="editorOptions" ng-model="code"></ui-codemirror>
它为此返回错误:ui-codemirror不能将对象或数组用作模型
如果我更改为JSON.stringify($scope.code)
,则代码镜像显示如下:
{ “名称”: “USER1”, “ID”: “34”, “值”:[3,5,4]}
但是,我希望它显示为:
{
"name": "user1", "id": "34", "value": [3, 5, 4] }
有什么帮助吗? 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.