【问题标题】:"orion" is undefined when integrating orion editor in dojo在 dojo 中集成 orion 编辑器时未定义“orion”
【发布时间】:2018-05-17 09:08:54
【问题描述】:

我是 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 文件夹中。

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

【问题讨论】:

    标签: dojo eclipse-orion


    【解决方案1】:

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

    检查this guide - 它有 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(这不会影响其他对象/模块)

    【讨论】:

    • 非常感谢。工作得很好。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多