0

我使用 CodeMirror 具有以下功能。

function app() {
    jQuery.get('http://localhost:2748/foo.txt', function (data) {
        alert(data);
    });
    alert(data);
    editor.setValue(data);
}

警报显示文本文件数据,但是当我将它们分配给编辑器时不显示。例如,如果我创建一个新变量t = "test";editor.setValue(t);然后它就可以工作。

4

1 回答 1

1

data在回调函数之外不可用。在回调中设置编辑器值:

function app() {
    jQuery.get('http://localhost:2748/foo.txt', function (data) {
        alert(data);
        editor.setValue(data);
    });
}
于 2012-07-18T18:32:53.927 回答