0

我是 dojo 的新手,我正在尝试在 dojo 中集成 orion 编辑器(从http://download.eclipse.org/orion/下载的构建),但我收到错误“orion”未定义。代码如下所示:

  1. 用于放置编辑器的 HTML 文件 <div data-dojo-attach-point="embeddedEditor"></div>

  2. 一个JS文件

    require([
    "dojo/_base/declare", 
    "dijit/_WidgetBase",
    "editorBuild/code_edit/built-codeEdit-amd",
    "dijit/_TemplatedMixin",
    "dojo/text!orionEditor.html"
    ], function(declare,_WidgetBase,
    codeEditorAmd, _TemplatedMixin,template){
    declare("orionEditor", [_WidgetBase, 
    _TemplatedMixin], {
    
    templateString: template,
    
    postCreate: function(){
          var codeEdit = new orion.codeEdit();
            var contents = '';
                codeEdit.create({parent: this.embeddedEditor, contentType: "application/javascript", contents: contents}).
          then(function(editorViewer) {                         
            if (editorViewer.settings) {
                            editorViewer.settings.contentAssistAutoTrigger = true;
                            editorViewer.settings.showOccurrences = true;
                        }
    
                    });
         }
       });
      });
    
  3. orion 编辑器构建放置在 editorBuild 文件夹中。

独立的 orion 工作正常 - http://libingw.github.io/OrionCodeEdit/ 当与 dojo 集成时,我不确定为什么 orion 未定义。任何帮助将非常感激。

4

1 回答 1

0

如果要orion在 amd 模块中使用名称,则必须将其定义为作为 require 回调传递的函数中的参数。

查看本指南- 它有 2 种将 orion 与 amd 模块一起使用的解决方案。

选项 1 - 定义一次捆绑包并在您需要的所有模块中使用较短的名称:

require.config({
    bundles: {
        "editorBuild/code_edit/built-codeEdit-amd": ["orion/codeEdit", "orion/Deferred"]
    }       
});
require(
    ["orion/codeEdit", "orion/Deferred"], 
    function(mCodeEdit, Deferred) {
        var codeEdit = new mCodeEdit();
        var contents = 'var foo = "bar";'; 
        codeEdit.create({parent: "embeddedEditor"/*editor parent node id*/})
                .then(function(editorViewer) {
                    editorViewer.setContents(contents, "application/javascript");
                });
});

选项 2 - 嵌套要求:

require(["editorBuild/code_edit/built-codeEdit-amd"], function() {
    require(["orion/codeEdit", "orion/Deferred"], function(mCodeEdit, Deferred) {
    var codeEdit = new mCodeEdit();
    var contents = 'var foo = "bar";'; 
    codeEdit.create({parent: "embeddedEditor"/*editor parent node id*/})
            .then(function(editorViewer) {
                editorViewer.setContents(contents, "application/javascript");
            });
    });
});

注意:您可以mCodeEdit用任何唯一名称替换(不会影响其他对象/模块)

于 2018-05-17T11:20:57.950 回答