0

当我设置dojoConfigasync: true,我DateTextBox的不会被渲染,但是当我使用时async: false一切正常;但我需要async能够使用 AJAX 长时间轮询的模式。如何解决此问题以便呈现我的控件?

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<style>
html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    padding: 0;
}
</style>
<script>dojoConfig = {async: true}</script>
<script src='dojo/dojo.js'>
</script>
<script>
require(["dojo/ready", "dijit/form/Button", "dojo/dom", "dijit/registry"], function(ready, Button, dom, registry){
    ready(function(){
        // Create a button programmatically:
            var myButton = new Button({
                label: "button"
            }, "topButton");
    });
});


require(["dojo/ready", "dijit/form/Button", "dojo/dom"], function(ready, Button, dom){
    ready(function(){
        // Create a button programmatically:
        var myButton = new Button({
            label: "button"
        }, "leftButton");
    });
});

require(["dojo/ready", "dijit/form/DateTextBox", "dojo/dom", "dojo/parser"], function(ready, DateTextBox, dom, parser){
    ready(function(){
        // Create a button programmatically:
        var dateTextBox = new DateTextBox({
            value: new Date(2009, 0, 20)
        }, "centerPicker");
    });
});

require(["dojo/ready", "dijit/form/Button", "dojo/dom"], function(ready, Button, dom){
    ready(function(){
        // Create a button programmatically:
        var myButton = new Button({
            label: "button"
        }, "bottomButton");
    });
});

require(["dojo/ready", "dijit/registry", "dijit/layout/BorderContainer", "dijit/layout/ContentPane"],
        function(ready, registry, BorderContainer, ContentPane){
            ready(function(){
                var appLayout = new BorderContainer({
                    design: "headline"
                }, "appLayout");
                 
                appLayout.addChild(
                    new ContentPane({
                        region: "top",
                        content: registry.byId("topButton")
                    })
                );
                appLayout.addChild(
                    new ContentPane({
                        region: "left",
                        content: registry.byId("leftButton")
                    })
                );
                appLayout.addChild(
                    new ContentPane({
                        region: "center",
                        content: registry.byId("centerPicker")
                    })
                );
                appLayout.addChild(
                    new ContentPane({
                        region: "bottom",
                        content: registry.byId("bottomButton")
                    })
                );
                 
                // start up and do layout
                appLayout.startup();
            });
        });
</script>
</head>
<body class="claro">
<style>
html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    padding: 0;
}

#appLayout {
    height: 100%;
}
</style>
<div id="appLayout" class="demoLayout"></div>
<button id="topButton" type="button"></button>
<button id="leftButton" type="button"></button>
<div id="centerPicker"></div>
<button id="bottomButton" type="button"></button>
</body>
</html>
4

1 回答 1

1

如果你构建了一层依赖,这个问题就会消失。问题是,DateTextBox 比 BorderContainer 具有更多的依赖关系 - 因此requireinputelement 的下载完成时间晚require于布局中的 ..

这反过来又使 dojo.ready 以“错误”的方式将回调排队,而不是您所希望的。一旦下载了所有依赖项,.ready 就有一个要调用的函数列表 - 但它是按照脚本对其进行排队的方式排序的。

为了克服这个问题,您可以使用“互斥锁”,因为在某些奇怪的情况下 - 订单可以根据您的设计需要排队。您必须使逻辑类似于:

  1. 给带有 region:center 的 ContentPane 一个 id。
  2. if registry.byId(centerPicker) != undefined: centerRegionContentPane.addChild(registry.byId(centerPicker))在布局部分。
  3. If registry.byId(centerRegion) != undefined: registry.byId(centerRegion).addChild(centerPickerWidget)在日期框部分下。
于 2012-10-04T19:46:22.297 回答