Ace编辑器JSON格式检查不能在" localhost://"

时间:2017-06-19 07:39:09

标签: javascript ace-editor

这是我在" file://":

中的代码

my code image. click and see

有效。但是,当我把它放在" 127.0.0.1"。

enter image description here

发生错误。获取http://localhost:8080/worker-json.js 404(未找到)

1 个答案:

答案 0 :(得分:0)

我已完成以下操作并修复了问题:

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

编辑:我每次创建Angular视图时都会遇到创建多个Web工作者的问题,因此通过快速搜索我发现了一个修复程序,以防止Ace多次创建Web worker,这是我的代码来初始化编辑:



  // 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);
  }




相关问题