How do I use getvalue using Ace Editor?

本秂侑毒 提交于 2020-01-01 16:07:29

问题


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.

I'm working on a local PHP file editor.. so open files etc, works fine, setcontent works like a charm. 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. If I use document.write it will not show the current information in the editor

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

Can someone please give me a little bit more information on what to do?


回答1:


Simply say:

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



回答2:


editor.getSession().getValue()

Where editor is the instance of the editor. If you're using jQuery along side of Ace, what I've been doing is preserving the editor instance on the DOM element.

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();


来源:https://stackoverflow.com/questions/9007742/how-do-i-use-getvalue-using-ace-editor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!