2017-05-31 177 views
0

我开始使用code mirror,我想显示一个对象结构的对象。CodeMirror如何显示对象结构的'javascript对象'字符串

我有一个文件与此内容

{ property1: 'value', property2: { property3: 'value' }} 

这是写在文本文件一行。

现在我想使用代码镜像,以便用户可以编辑此文件内容。 我得到使用HTTP调用该文件的内容之后,我有这样的代码

 var editor = CodeMirror(document.getElementById('reportEditor'), { 
      mode: { name: "javascript", json: true }, 
      theme: "default", 
      lineNumbers: true, 
      readOnly: false, 
      value: JSON.stringify(response.data), 
     }); 

这工作得很好,我得到了一个线上的内容,但是代码镜显示它。

如何强制代码镜像像

{ 
     property1: 'value', 
     property2: { 
      property3: 'value' 
     } 
} 

回答

0

的关键是这里JSON.stringify(response.data, null, "\t")现在有JSON格式