简体   繁体   English

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

[英]Using CodeMirror. "Cannot set property 'modeOption' of undefined"

Currently running into an issue with this.目前遇到了这个问题。

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;
    });

Here is my code.这是我的代码。

It is happening due to TextArea object's value field is undefined and thus inside the CodeMirror codemirror.js library options.value is initialising the doc variable also undefined, and thus later in source modeOption is getting matched with doc child field (if the doc is undefined, how a object key may exists).这是因为TextArea对象的 value 字段undefined ,因此在CodeMirror codemirror.jsoptions.value初始化doc变量也未定义,因此稍后在源模式中modeOption与 doc 子字段匹配(如果 doc 未定义,对象键如何存在)。

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,
});

Hope this may help someone.希望这可以帮助某人。

问题是document.getElementById('config_data_editor')不是 textarea。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM