道场上传拖放(Dojo Uploader with Drag and Drop)

2019-09-29 06:01发布

我试图重建这个例子在我的项目,要添加拖放功能道场上传:

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

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

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

返回未定义addDropTarget和iframe的uploadType。 我用不同的浏览器试了一下,甚至还添加了力:HTML5的上传,但什么都没有改变。

请注意,一切工作正常,除了从DND。

我使用道场1.8.1。

Answer 1:

在道场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/



文章来源: Dojo Uploader with Drag and Drop