How to use getvalue using Ace Editor?

I use the Ace editor, but I do not use JavaScript much, so it’s hard for me to get it working without the proper documentation.

I am working on a local PHP file editor. Therefore, open files, etc. work great, setcontent works like a charm. But now I want to save the editor information back to the file.

Not in itself a problem. But how can I get the var code. If I use document.write, it will not show the current information in the editor

If I could print 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 more information on what to do?

+2
javascript editor ace-editor
source share
2 answers

Just say:

editor.getSession().on('change', function(){ editor.getSession().getValue(); }); 
+6
source share

editor.getSession().getValue()

Where editor is the editor instance. If you use jQuery next to Ace, then what I did was save the editor instance in the DOM element.

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

Later, if you need to return the value back, you can just do ...

 $('#editor').data('editor').getSession().getValue(); 
+2
source share

All Articles