无法获取到dijit表单时的参考形式有文字框(Cannot get a reference to a

2019-10-18 13:33发布

我有麻烦的dijit表单控件时的参考表格中有一个文字框。 下面的代码片段演示了此问题。 在执行时,警告框说“不确定”。 不过,如果我摆脱<input ... id="dateTextBox"... />我能去的表单控件的引用。

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dijit/themes/claro/claro.css" media="screen">

        <!-- load dojo and provide config via data attribute -->
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/dojo/1.9.1/dojo/dojo.js"
            data-dojo-config="async: true, parseOnLoad: true">
        </script>
        <script type="text/javascript">
            require(["dijit/form/TextBox", "dijit/form/DateTextBox"]);
        </script>

        <script type="text/javascript">
            require(["dojo/parser", "dijit/registry", "dijit/form/Form", "dojo/domReady!"],
            function(parser, registry) {
                parser.parse();
                alert(registry.byId("frm_test"));
            });
        </script>
    </head>

    <body class="claro">
        <div data-dojo-type="dijit/form/Form" id="frm_test" encType="multipart/form-data" action="" method="">  
            <input type="text" id="textBox" name="textBox" data-dojo-type="dijit/form/TextBox" />
            <input type="text" id="dateTextBox" name="dateTextBox" data-dojo-type="dijit/form/DateTextBox" />
        </div>
    </body>
</html>

Answer 1:

我建议包裹registry.byIdready调用。

保持parse onLoad: true ,删除

require(["dijit/form/TextBox", "dijit/form/DateTextBox"]); 

作为分析器将自动需要(当道场> = 1.8),并使用以下:

<script type="text/javascript">
    require(["dojo/ready", "dijit/registry", "dojo/domReady!"],
        function(ready, registry) {
            // by default the prioirty of this ready call will be after the 
            // ready call used to parse when parseOnLoad is true
            ready(function() { 
                alert(registry.byId("frm_test"));
            });
    });
</script>

需要注意的是等待道场/ domready中! 火灾与部件工作时往往是不足够的。 很多部件应该初始化或访问,直到以下模块加载和执行:

  • 道场/ uacss
  • 的dijit / hccss
  • 道场/分析器

因此,与部件工作时,你通常应该把你的代码道场/就绪()回调的内

http://dojotoolkit.org/reference-guide/1.9/dojo/domReady.html

http://dojotoolkit.org/reference-guide/1.9/dojo/ready.html#dojo-ready



文章来源: Cannot get a reference to a dijit form when the form has a DateTextBox