0

作为 Dojo 的新手,我正在尝试使用值初始化 Dijit 表单,例如从存储读取、XHR 等。

但是,调用会导致http://yandex.st/dojo/1.7.3/dojox//form/manager/_Mixin.js抛出form.setFormValues()错误TypeError: invalid 'in' operand this.formWidgets

有什么我做错了还是这是Dojo问题?(完整的示例也可以在这里找到:http: //pastebin.com/7LUHr3iA

<!-- language-all: lang-html -->
`
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.7.3/dijit/themes/claro/claro.css" media="screen">

    <script type="text/javascript">
        dojoConfig = {async: true,parseOnLoad: true};
    </script>
    <script type="text/javascript" src="http://yandex.st/dojo/1.7.3/dojo/dojo.js"></script>

    <script type="text/javascript">
        require(["dijit/form/TextBox","dijit/form/Button","dojox/form/Manager",
                "dojo/parser","dojo/dom","dijit/registry"], function () {});
    </script>
</head>
<body class="claro">

    <form id="myForm" method="post" data-dojo-type="dojox.form.Manager">

        <label for="name">Name</label>
        <input id="name" name="nameField" data-dojo-type="dijit.form.TextBox"/><br/>

        <label for="surname">Surname</label>
        <input id="surname" name="surnameField" data-dojo-type="dijit.form.TextBox"/><br/>

        <button data-dojo-type="dijit.form.Button">Submit</button>

        <script type="dojo/method" event="startup">
            var form = dijit.byId("myForm");

            form.setFormValues({
                nameField: "Hello",
                surnameField: "World"
            });
        </script>
    </form>
</body>
</html>
`
4

1 回答 1

0

Dojo 1.7 是异步的。代码应采用以下形式:

require(["dependency"], function(dep) {
  // use dependency
});

当您尝试在页面下方进一步引用它时,没有理由相信dojox/form/Manager会加载。

注册表是引用小部件的正确方法,而不是表单的 1.6 样式代码dijit.byId。请参阅livedocs

另请参阅dojo/domReady!插件。

于 2012-08-14T15:28:40.247 回答