我有一个 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 cannot use an object or an array as a model
如果我更改为JSON.stringify($scope.code)
,代码镜像显示如下:
{"name":"user1","id":"34","value":[3,5,4]}
但是,我希望它显示为:
{
"name": "user1", "id": "34", "value": [3, 5, 4] }
有什么帮助吗?谢谢