How to save or edit javascript files in ace editor

冷暖自知 提交于 2019-12-02 23:13:26

问题


I want to use the Ace editor to save and edit javascript files it's not clear in the documentation how to do that.


回答1:


Ace editor is only the UI part of the editor. Think of it as: like a textarea but cool!.
To deal with files you need some kind of server that will read and save the files and will send the text to the webpage where Ace lives. (You can also use html5 filesystem api, but that only works on chrome).
You can find many interesting implementations of this in Zed source code at https://github.com/zedapp/zed/tree/master/app/js/fs, which is a code editor based on Ace.




回答2:


Lets say you have a button called download, this is how you would do it

I am using the filesaver.js library that you can find HERE

document.getElementById("download").addEventListener("click", ()=>{
      var file = new File([editor.getValue()], "zup.js", {type: "text/plain;charset=utf-8"});
      saveAs(file);
})


来源:https://stackoverflow.com/questions/25463106/how-to-save-or-edit-javascript-files-in-ace-editor

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