简体   繁体   中英

Ace Editor JSON format check not work in “localhost://”

This is my code in "file://":

我的代码图像。点击查看

It works. But when I put it on the "127.0.0.1".

在此处输入图片说明

There was an error. GET http://localhost:8080/worker-json.js 404 (Not Found)

I've done the following and the problem fixed:

ace.config.set("workerPath", "assets/js/plugins/editors/ace/")

Edit: I was facing an issue with multiple web workers being created each time Angular view is created, so with a quick search I found also a fix to prevent Ace from creating web workers multiple times, here is my code to init the editor:

  // Code running with Angular 4 CLI and WebPack updateSkecthCalcPanel() { const editor = ace.edit(this.canvasObject.sketchCalcEditor); // Selector name const aceSession = editor.getSession(); ace.config.set("workerPath", "assets/js/plugins/editors/ace/") // Folder contain the worker editor.setTheme("ace/theme/monokai"); editor.setShowPrintMargin(false); editor.setOptions({ readOnly: true, maxLines: Infinity }); aceSession.setMode("ace/mode/json"); aceSession.setValue(js_beautify(JSON.stringify(this.sketchObject), { indent_size: 2 })); // Quick-fix that allows to omit ACE problem with loading workers ace.require("ace/edit_session").EditSession.prototype.$startWorker = function () { } // Fold Code window.setTimeout(function () { aceSession.foldAll(1, aceSession.getLength()); }, 500); } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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