2012-07-18 23 views
0

我使用CodeMirror具有以下功能。CodeMirror使用jQuery導入文本

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

該警報顯示文本文件數據,但是當我將它們分配給編輯器時不顯示。如果我例如我做一個新的變量t = "test";,然後editor.setValue(t);然後它的工作。

回答

1

您的data在回調函數外部不可用。在您的回撥中設置編輯器值:

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