Dojo Uploader with Drag and Drop

时间:2013-08-13 13:39:13

标签: file-upload dojo drag-and-drop uploader

我想在我的项目中重新创建这个示例,将拖放功能添加到dojo上传器中:

  

http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/form/tests/test_Uploader.html

在jsfiddle或我的应用程序中复制完全相同的代码行

if(uploader.addDropTarget && uploader.uploadType=='html5'){

为uploadType的addDropTarget和iframe返回undefined。 我尝试使用各种浏览器,甚至在上传器中添加了force:html5,但没有任何改变。

请注意,除了dnd之外,一切正常。

我正在使用dojo 1.8.1。

1 个答案:

答案 0 :(得分:4)

在dojo 1.8中,上传器尚未完全符合AMD标准。因此,为了使主干测试中的示例在1.8中工作,您需要使用dojox.form.Uploader构造函数而不是所需的AMD模块以编程方式创建上载器。如下:

<form method="post" action="UploadFile.php" id="myForm" enctype="multipart/form-data" >
    <fieldset>
        <legend>DnD Test</legend>
        <input class="browseButton" id="uploader"/>
        <input type="submit" label="Submit" data-dojo-type="dijit/form/Button" />
        <div id="files" data-dojo-type="dojox/form/uploader/FileList" data-dojo-props='uploaderId:"uploader"' ></div>
    </fieldset>
</form>

<div id="dropTarget">Drop files here !</div>

在javascript中:

require([
    'dojo/parser',
    'dojo/dom',
    'dijit/registry',
    'dojox/form/Uploader',
    'dojox/form/uploader/FileList',
    'dojox/form/uploader/plugins/HTML5',
    'dojo/domReady!'
], function(parser, dom, registry, ready){

    var dropTarget = dom.byId('dropTarget'), uploader;

    parser.parse().then(function(){

        // You need to use dojox.form.Uploader, as in dojo 1.8, 
        // the module is not fully AMD compliant yet.

        uploader = new dojox.form.Uploader({
            name:'uploadedfile', 
            label:'Select Some Files',
            multiple:true, 
            force:'html5'
        }, 'uploader');

        uploader.startup();

        if(require.has('file-multiple')){
            console.debug("Adding a new drop target");
            registry.byId('uploader').addDropTarget(dropTarget); 
        }
    });
});

请参阅http://jsfiddle.net/psoares/6r2jZ/