Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 代码镜像&x27;s onLoad功能不工作?_Javascript_Codemirror - Fatal编程技术网

Javascript 代码镜像&x27;s onLoad功能不工作?

Javascript 代码镜像&x27;s onLoad功能不工作?,javascript,codemirror,Javascript,Codemirror,只是好奇是否有人以前安装过CodeMirror,并让onLoad功能正常工作。在最新版本中,它无法正常工作。这是我的密码: cydonia.editor = CodeMirror.fromTextArea('query', { height: $('#query-text-space').css('height'), parserfile: ["tokenizexquery.js", "parsexquery.js" ], stylesheet: ["/common/co

只是好奇是否有人以前安装过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');

    }
}); 

谢谢

查看代码时,我没有找到任何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)中。

查看代码,我没有找到任何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
  });

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

只需指定函数名,请参阅下面的代码

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");
}

只需指定函数名,请参见下面的代码

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");
}
显然,CodeMirror“是同步加载的,所以一旦构造函数返回,您就可以使用它了。”

我无法使用fromTextArea方法运行任何内容,但以下方法对我有效:

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

我已使用fromTextArea()成功地使其工作。最初,内容没有出现,但使用mycdemError.refresh();修正了这个问题

var myCodeMirror = CodeMirror.fromTextArea(el);
// onLoad script here
myCodeMirror.refresh();
显然,CodeMirror“是同步加载的,所以一旦构造函数返回,您就可以使用它了。”

我无法使用fromTextArea方法运行任何内容,但以下方法对我有效:

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

我已使用fromTextArea()成功地使其工作。最初,内容没有出现,但使用mycdemError.refresh();修正了这个问题

var myCodeMirror = CodeMirror.fromTextArea(el);
// onLoad script here
myCodeMirror.refresh();

我发现由于某种原因你不能传递这样的函数。所以我就这样设置了一个变量:我发现由于某种原因,你不能传递这样的函数。所以我就这样设置了一个变量:这就是我写的从最新的补丁0.92开始,您现在可以向它传递一个函数,就像在这两个示例中一样。codeMirrorLoaded()立即执行函数,而不等待onLoad事件。@如果是正确的,答案确实是错误的。您肯定会看到警报,因为您执行函数而不是将其作为回调传递。如果需要将其作为回调传递,则应该编写类似于
onLoad:codemirrorload
,而不是
onLoad:codemirrorload()
。这基本上就是我编写的内容。=)从最新的补丁0.92开始,您现在可以向它传递一个函数,就像在这两个示例中一样。codeMirrorLoaded()立即执行函数,而不等待onLoad事件。@如果是正确的,答案确实是错误的。您肯定会看到警报,因为您执行函数而不是将其作为回调传递。如果需要将其作为回调传递,则应该编写类似于
onLoad:codemirrorload
,而不是
onLoad:codemirrorload()