简体   繁体   English

Dojo:“定制”窗口小部件内的布局窗口小部件

[英]Dojo : Layout widgets inside the Custom widget

I have a Custom dojo widget with dojo layout widgets 我有一个带有dojo布局小部件的Custom dojo小部件

template as below 模板如下

<div>
    <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="gutters:false" id="mainPanel" style="padding: 0px">
        <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top', splitter:false"  style="padding: 0px">
            Saartha Labs Pvt Ltd
        </div>
        <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top', gutters: false, splitter:false"  style="padding: 0px" >
            <div id="toolBar"></div>
        </div>
        <div id="map-div"  data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center', splitter:false"></div>
        <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'bottom', splitter:false" style="display: none" ></div>
    </div>
</div>

and the Custom Widget as below "Canvas.js" 和自定义小部件,如下“ Canvas.js”

define([
    "dojo/_base/declare",
    "dijit/_WidgetBase",
    "dijit/_WidgetsInTemplateMixin",
    "dijit/_OnDijitClickMixin",
    "dijit/_TemplatedMixin",
    "dojo/text!./canvas.html",

    "dijit/layout/BorderContainer",
    "dijit/layout/ContentPane"
], function (declare, _WidgetBase,_WidgetsInTemplateMixin, _OnDijitClickMixin,_TemplatedMixin, template) {

    return declare([_WidgetBase,_OnDijitClickMixin, _TemplatedMixin,_WidgetsInTemplateMixin], {
        templateString: template
        //  your custom code goes here

    });

});

When use try to use the Canvas with new it throws a error as below. 使用时,尝试将Canvas与新画布一起使用时,会引发如下错误。

require([
        "bhuvi/canvas/Canvas",
        "dojo/domReady!"],
            function(Canvas){
                var canvas = new Canvas();
                canvas.placeAt(window.document.body);
            });

Error as 错误为

"Tried to register widget with id==mainPanel but that id is already registered" “试图使用id == mainPanel注册小部件,但该ID已被注册”

Never use IDs in your widget templates. 切勿在小部件模板中使用ID。 IDs must be unique, so unless your ID is dynamically generated (which isn't in this case), your ID won't be unique if you create multiple instances of your widget. ID必须是唯一的,因此,除非您的ID是动态生成的(在这种情况下不是这样),否则如果您创建窗口小部件的多个实例,则ID不会是唯一的。

In stead of that, use the data-dojo-attach-point mechanism, for example: 取而代之的是,使用data-dojo-attach-point机制,例如:

<div>
    <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="gutters:false"
        data-dojo-attach-point="mainPanel" style="padding: 0px">
        <!-- Rest of the code -->
    </div>
</div>

Now you can use this.mainPanel if you need access to that widget. 现在,如果需要访问该小部件,则可以使用this.mainPanel

Even if you don't create multiple instances of your widget, you're still better off by using the attach points, you never know what happens behind the screens. 即使您不创建窗口小部件的多个实例,通过使用附加点仍然会更好,但您永远都不知道屏幕后面会发生什么。


A small side note: Layout widgets are not officially supported by the dijit/_WidgetsInTemplateMixin mixin, so be careful when using them. 一个小小的注意事项: dijit/_WidgetsInTemplateMixin mixin并不正式支持布局小部件,因此在使用它们时要小心。 However, this is not the cause of your problem. 但是,这不是您的问题的原因。

var dojoConfig = {
            async: true,
            parseOnLoad: false
}

parseOnLoad should be false parseOnLoad应该为false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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