【问题标题】:codemirror option from a variable变量中的 codemirror 选项
【发布时间】:2012-11-14 18:29:03
【问题描述】:

使用 codemirror 2,我有一些选项,例如 lineNumbers、gutter 等...我想知道如何设置那些读取变量的选项,例如:

var ln = 'true';
editor = CodeMirror.fromTextArea(textarea.get(0), {
        height : "140px",
        lineWrapping : true,
        lineNumbers : ln,
        gutter : true,
        mode: 'application/xml',    
    }

这个想法是,你用你希望与 codemirror 一起使用的选项填写一个 php 表单,然后 cm 使用这些选项构建 textarea。

lineNumbers : ln 似乎不起作用...它对 textarea 没有影响

如何在加载代码镜像之前让 vars 设置选项?

【问题讨论】:

  • 您忘记提问了吗?

标签: php textarea codemirror


【解决方案1】:

您的选项确实可以提前构建并传入。上面示例的唯一错误是变量 ln 已设置为字符串 'true' 而不是布尔值 true。

var ln = true; //not string 'true';
var options = {
    height : "140px",
    lineWrapping : true,
    lineNumbers : ln,
    gutter : true,
    mode: 'application/xml',  
}
var editor = CodeMirror.fromTextArea(textarea.get(0), options);

【讨论】:

    猜你喜欢
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多