使用代码镜像。“无法设置未定义的属性‘modeOption’”

Ove*_*119 2 javascript

目前遇到了这个问题。

const configDataNode = document.getElementById('config_data');
    const editor = CodeMirror.fromTextArea(
      document.getElementById('config_data_editor'),
      {
        // lineNumbers: true,
        mode: 'javascript',
        // tabSize: 2,
        // indentWithTabs: true,
        // value: JSON.stringify(gon.config.initialData, 2, 2),
      },
    );
    editor.on('change', changeObject => {
      const {text} = changeObject;
      configDataNode.value = text;
    });
Run Code Online (Sandbox Code Playgroud)

这是我的代码。

Ari*_*afa 6

这是由于TextArea对象的值字段是undefined,因此在CodeMirror codemirror.js库内部options.value初始化doc变量也是未定义的,因此稍后在源modeOption中与文档子字段匹配(如果文档未定义,对象键可能如何存在)。

var textarea_editor = document.getElementById("RichTextArea");

// so explicitly assign value to textarea object.
textarea_editor.value = "";


this.editor = CodeMirror.fromTextArea(textarea_editor, {
     tabSize: 4,
     mode: 'text/plain',
     theme: 'default',
     lineNumbers: true,
     styleActiveSelected: true,
     styleActiveLine: true,
     indentWithTabs: true,
     matchBrackets: true,
     highlightMatches: true,
});
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助某人。