我找不到有关以编程方式创建dojox / form / Uploader的任何文档。我自己尝试过,但看起来插件注册机制有些破损。
require([ "dojo/dom-construct", "dijit/form/Button", "dojox/form/Uploader", "dojox/form/uploader/FileList", "dojox/form/uploader/plugins/IFrame", "dojo/domReady!" ], function(domConstruct, Button, Uploader, UploaderFileList) { var form = domConstruct.create('form', { method: 'post', enctype: 'multipart/form-data', class: 'Uploader' }, document.body); var up = new Uploader({ label: 'Pick files', multiple: true, url: '/echo/json/' }).placeAt(form); var list = new UploaderFileList({ uploader: up }).placeAt(form); var btn = new Button({ type: 'submit', label: 'upload', onClick: function() { up.upload(); } }).placeAt(form); btn.startup(); up.startup(); list.startup(); });
此处的 jsfiddle示例。
据我了解,dojox / form / Uploader和dojox / form / uploader / plugins / IFrame的源代码是通过dojox.form.addUploaderPlugin函数注册的,该函数使用self和plugged插件重新声明Uploader小部件类。前辈。但是,上传器窗口小部件的关键方法“上传”永远不会被HTML5插件(该文件自动包含在Iframe插件中)覆盖。
这是错误吗?还是我做错了什么?
谢谢你的帮助!
简而言之; 使用新的dojox.form.Uploader而不是pull in变量,否则扩展插件不适用。
原因是,您会看到程序员在addUploaderPlugin中执行以下操作:
dojox.form.UploaderOrg = dojox.form.Uploader; var extensions = [dojox.form.UploaderOrg]; dojox.form.addUploaderPlugin = function(plug){ extensions.push(plug); declare("dojox.form.Uploader", extensions, {}); }
AMD loader返回的类将始终是dojox.form.UploaderOrg,并且不知道扩展插件。
更改为以下内容:
var up = new dojox.form.Uploader({ label: 'Pick files', multiple: true, url: '/echo/json/' }).placeAt(form);
并确保您 没有 设置djConfig.publishRequireResult = false
djConfig.publishRequireResult = false