2

只是好奇之前是否有人设置过 CodeMirror 并让 onLoad 函数工作。使用最新版本,它无法正常工作。这是我的代码:

cydonia.editor = CodeMirror.fromTextArea('query', {
    height: $('#query-text-space').css('height'),
    parserfile: ["tokenizexquery.js", "parsexquery.js" ],
    stylesheet: ["/common/codemirror/css/xmlcolors.css", "/common/codemirror/css/xqcolors.css"],
    path: "/common/codemirror/js/",
    continuousScanning: false, //500,
    lineNumbers: true,
    onLoad: function (n) {
        alert('loaded');

    }
}); 

谢谢!!!

4

3 回答 3

1

查看代码我没有找到任何 onload 函数:

   setDefaults(CodeMirrorConfig, {
    stylesheet: [],
    path: "",
    parserfile: [],
    basefiles: ["util.js", "stringstream.js", "select.js", "undo.js", "editor.js", "tokenize.js"],
    iframeClass: null,
    passDelay: 200,
    passTime: 50,
    lineNumberDelay: 200,
    lineNumberTime: 50,
    continuousScanning: false,
    saveFunction: null,
    onChange: null,
    undoDepth: 50,
    undoDelay: 800,
    disableSpellcheck: true,
    textWrapping: true,
    readOnly: false,
    width: "",
    height: "300px",
    minHeight: 100,
    autoMatchParens: false,
    parserConfig: null,
    tabMode: "indent", // or "spaces", "default", "shift"
    enterMode: "indent", // or "keep", "flat"
    electricChars: true,
    reindentOnLoad: false,
    activeTokens: null,
    cursorActivity: null,
    lineNumbers: false,
    firstLineNumber: 1,
    indentUnit: 2,
    domain: null,
    noScriptCaching: false
  });

我知道它在手册中,但不在代码中(codemirror.js)。

于 2010-12-16T11:24:21.143 回答
1

显然,CodeMirror“同步加载,所以只要构造函数返回,你就可以使用它。” https://groups.google.com/forum/#!topic/codemirror/oXEdDS5ef64

我无法使用 fromTextArea 方法运行任何东西,但以下方法对我有用:

var myCodeMirror = CodeMirror(function(elt) {
    el.parentNode.replaceChild(elt, el);
    // onLoad script here
}, {
    value: el.value
});

[更新]

我已经设法使用 fromTextArea() 让它工作。最初内容没有出现,而是使用 myCodeMirror.refresh(); 解决了这个问题。

var myCodeMirror = CodeMirror.fromTextArea(el);
// onLoad script here
myCodeMirror.refresh();
于 2013-08-01T10:28:36.487 回答
-3

Just specify function name, see the code below

cydonia.editor = CodeMirror.fromTextArea('query', {
    height: $('#query-text-space').css('height'),
    parserfile: ["tokenizexquery.js", "parsexquery.js" ],
    stylesheet: ["/common/codemirror/css/xmlcolors.css", "/common/codemirror/css/xqcolors.css"],
    path: "/common/codemirror/js/",
    continuousScanning: false, //500,
    lineNumbers: true,
    onLoad: codeMirrorLoaded()
}); 

function codeMirrorLoaded(){
    alert("loaded");
}
于 2010-12-30T21:15:15.723 回答