简体   繁体   English

如何使用Ace Editor使用getvalue?

[英]How do I use getvalue using Ace Editor?

I am using the Ace Editor, but I do no use JavaScript a lot so I'm finding it hard to make it actually work without a proper documentation. 我正在使用Ace编辑器,但我没有使用JavaScript很多,所以我发现很难让它在没有适当文档的情况下实际工作。

I'm working on a local PHP file editor.. so open files etc, works fine, setcontent works like a charm. 我正在研究一个本地的PHP文件编辑器..所以打开文件等,工作正常,setcontent就像一个魅力。 But now I want to save the editor's information back to the file. 但现在我想将编辑器的信息保存回文件中。

In itself not really a problem. 本身并不是一个真正的问题。 But how do I retrieve the var code. 但是我如何检索var代码。 If I use document.write it will not show the current information in the editor 如果我使用document.write,它将不会在编辑器中显示当前信息

If I could print out what is in the editor I could save the data. 如果我可以打印出编辑器中的内容,我可以保存数据。 But I don't know how to provide a valid callback for getValue 但我不知道如何为getValue提供有效的回调

Can someone please give me a little bit more information on what to do? 有人可以给我一些关于该做什么的更多信息吗?

Simply say: 简单地说:

editor.getSession().on('change', function(){ 
         editor.getSession().getValue(); 
});

editor.getSession().getValue()

Where editor is the instance of the editor. editoreditor的实例。 If you're using jQuery along side of Ace, what I've been doing is preserving the editor instance on the DOM element. 如果你在Ace旁边使用jQuery,我一直在做的是保留DOM元素上的编辑器实例。

var editor = ace.edit('...');
$('#editor').data('editor', editor);

Later on if you need to get the value back you can then just do... 如果你需要获得价值,那么稍后你可以做...

$('#editor').data('editor').getSession().getValue();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM