我找不到任何有关以编程方式创建 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 小部件类作为其前辈。但是 Uploader 小部件的关键方法“上传”永远不会被 HTML5 插件(它自动包含在 iframe 插件中)覆盖。
这是错误吗?或者我做错了什么?
谢谢你的帮助!