最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using CodeMirror. "Cannot set property 'modeOption' of undefined" - Stack Overflo

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Dec 25, 2020 at 14:14 Abdelsalam Shahlol 1,7791 gold badge24 silver badges33 bronze badges asked Dec 30, 2018 at 22:26 Overload119Overload119 5,4265 gold badges32 silver badges37 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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).

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.

The issue was that document.getElementById('config_data_editor') is not a textarea.

发布评论

评论列表(0)

  1. 暂无评论