尝试创建一个将创建表单的dojo小部件

时间:2015-07-27 14:37:10

标签: javascript dojo

我想把它放在我放置data-dojo-type =" js / widget / SAUploadForm"对于上传小部件,它将在那里生成一个表单。由于页面上没有生成任何表单,因此不确定我现在的错误。

<html>
<head>
<title>Upload</title>
<script>
    dojoConfig = {
        async : true,
        parseOnLoad : false
    }
</script>
<script src="js/dojo/dojo.js"></script>
</head>
<body>
<div>
    <h1 align="center">Upload</h1>
    <br />
    <div data-dojo-type="js/widget/SAUploadForm"></div>
</div>
</body>
</html>

我的小部件文件:SAUploadForm.js

define(["dojo/_base/declare", "dojo/dom-construct", "dojo/parser", "dijit/_WidgetBase", "dijit/_TemplatedMixin"],
    function(declare, domConstruct, parser, ready, _WidgetBase, _TemplatedMixin) {
        decalre("SAUploadForm", [_WidgetBase, _TemplatedMixin], {
            formString: '<form method="post" enctype="multipart/form-data" action="/webapp/upload">' +
            '<table>' + 
                '<tr>' + 
                    '<td>File:</td>' + 
                    '<td><input type="file" name="file" value="Browse" accept=".sub" /></td>' + 
                '</tr><tr>' + 
                    '<td colspan="2"><button type="submit">Upload</button></td>' + 
                '</tr>' + 
            '</table></form>',


            buildRendering: function() {
                this.domNode.innerHTML = formString;
            }
        });

        ready(function() {
            parser.parse();
        });
});

这位于js / widget /

1 个答案:

答案 0 :(得分:0)

那么, 这里有太多错误的东西......

  • 有一个拼写错误:decalre而不是declare
  • 您应该使用templateString而非自定义formString
  • 如果您希望解析器了解它,则必须要js/widget/SAUploadForm
  • 您声明ready但您不需要
  • 应返回declare的结果

这样的事情应该有效:
(注意:片段无法工作,因为代码需要将窗口小部件放入单独的文件中)

&#13;
&#13;
//This goes into js/widget/SAUploadForm.js
define(["dojo/_base/declare", "dojo/dom-construct", "dijit/_WidgetBase", "dijit/_TemplatedMixin"],
    function(declare, domConstruct, _WidgetBase, _TemplatedMixin) {
       return declare("js/widget/SAUploadForm", [_WidgetBase, _TemplatedMixin], {
            templateString: '<form method="post" enctype="multipart/form-data" action="/webapp/upload">' +
            '<table>' + 
                '<tr>' + 
                    '<td>File:</td>' + 
                    '<td><input type="file" name="file" value="Browse" accept=".sub" /></td>' + 
                '</tr><tr>' + 
                    '<td colspan="2"><button type="submit">Upload</button></td>' + 
                '</tr>' + 
            '</table></form>'
        });
});

//this goes into the index.html file
require(["dojo/parser", "dojo/domReady!", "js/widget/SAUploadForm"], function(parser) { 
  parser.parse();
});
&#13;
<script>
    dojoConfig = {
        async : true,
        parseOnLoad : false
    }
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<div>
    <div data-dojo-type="js/widget/SAUploadForm"></div>
</div>
&#13;
&#13;
&#13;