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

関数名を指定するだけです。以下のコードを参照してください。

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 に答える