javascript - 使用 CodeMirror。“无法设置未定义的属性‘modeOption’”
问题描述
目前遇到了这个问题。
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;
});
这是我的代码。
解决方案
这是由于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,
});
希望这可以帮助某人。
推荐阅读
- azure - Azure VM 处于联机状态,但该 VM 的 Azure devops 代理处于脱机状态
- angular - 问题更改根并且在角度之后不更改页面
- javascript - 如何解决“无法解决:App.vue 中的组件”
- flutter - 打印功能在 Flutter Stateless Widget 中不起作用
- parent-child - 我可以用 LineNbr 值填充字段 artran.OrigInvoiceLineNbr 吗?
- r - 是否可以从具有线和点几何数据的 ggplot 的图例中删除绘制为点几何的组?
- jquery - 为什么可以为 svg fill 分配一个数组作为其值?在这种情况下,数组会做什么?
- c# - 如何将命令行参数传递给 Windows 服务的 MSI 文件
- python - 与不匹配的类数和 target_names 相关的错误
- python - 嵌套循环给出了多个问题