How to save or edit javascript files in ace editor

て烟熏妆下的殇ゞ 提交于 2019-12-02 14:11:15

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.

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