Dojo: BorderContainer and ContentPanes not working inside of a custom widget template

吃可爱长大的小学妹 提交于 2020-01-02 08:44:09

问题


Hey guys, im trying to create some custom templated widgets with dijit.layout objects (BorderContainer, ContentPane) in the template, and i just can't get it to work. Maybe SO can steer me in the right direction... here's my code so far:

test.html

<html>
<head>
<title>Test Page</title>
    <style type="text/css">
        @import "http://ajax.googleapis.com/ajax/libs/dojo/1.4.1/dojo/resources/dojo.css";
        @import "http://ajax.googleapis.com/ajax/libs/dojo/1.4.1/dijit/themes/tundra/tundra.css";
        html, body, #page {
            width: 100%; height: 100%; overflow: hidden;
        }
    </style>
    <script type="text/javascript">
        var djConfig = {
            isDebug: false,
            parseOnLoad: true,
            baseUrl: './',
            modulePaths: {'test' : '.'}
        };
    </script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.4.1/dojo/dojo.xd.js"></script>
<script type="text/javascript" src="test.js"></script>
<script>
    dojo.require('dijit.layout.BorderContainer');
    dojo.require('dijit.layout.ContentPane');
    dojo.require('test.testWidget');
    dojo.ready(function() {
        var widget = new test.testWidget({}, 'widgetGoesHere');
    });
</script>
</head>
<body class="tundra">
    <div id='widgetGoesHere'></div>
</body>
</html>

testWidget.js

dojo.provide('test.testWidget');
dojo.require('dijit._Widget');
dojo.require('dijit._Templated');
dojo.require('dijit.layout.BorderContainer');
dojo.require('dijit.layout.ContentPane');
dojo.declare('test.testWidget', [ dijit._Widget, dijit._Templated],  {
    templatePath: dojo.moduleUrl('test', 'testWidget.html'),
    widgetsInTemplate: true,

    postCreate: function() {
        this.inherited(arguments);
    }
});

testWidget.html

<div id="page" dojoType="dijit.layout.BorderContainer" liveSplitters="true" design='sidebar' style="height:100%;">
    <div dojoType="dijit.layout.ContentPane" region='center'>
        test center
    </div>
    <div dojoType="dijit.layout.ContentPane" region='left' style="width:50%">
        test left
    </div>
</div>

Sorry for the rather code-verbose post, but i dont know why it doesnt work so i can't really describe my problem in just words.

The jist is i want two panes, a 'left' (region='center' in this case) pane, and a 'right' pane that i can put widget content in. The above code simply renders the text in the divs with no panes at all.


回答1:


I mixin the following in my custom widgets :

dijit.layout._LayoutWidget, dijit._Templated, dijit._Container

Container allows you to contain other dijits like BorderContainer. Templated allows you to put your widget markup in a html template. LayoutWidget allow you to get all the dijit layout and resize goodies.

If you are using dojo 1.4, templatePath can/should now be:

templateString : dojo.cache("test", "testWidget.html")

In your template you need a top level containerNode (this gets replaced by the dojo parser on widget creation I think) so testWidget's template would become:

<div dojoAttachPoint="containerNode" style="height:100%;">
<div id="page" dojoType="dijit.layout.BorderContainer" liveSplitters="true" design='sidebar' style="height:100%;width:100%;" dojoAttachPoint="subContainerWidget">
    <div dojoType="dijit.layout.ContentPane" region='center'>
            test center
    </div>
    <div dojoType="dijit.layout.ContentPane" region='left' style="width:50%">
            test left
    </div>
</div>



来源:https://stackoverflow.com/questions/3102594/dojo-bordercontainer-and-contentpanes-not-working-inside-of-a-custom-widget-tem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!