我找不到任何关于以编程方式创建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 here的示例。
据我了解,dojox / form / Uploader和dojox / form / uploader / plugins / IFrame的源代码,该插件通过dojox.form.addUploaderPlugin函数注册,该函数使用self和plugged重新声明Uploader小部件类插件作为其前身。 但是上传器小部件的关键方法“上传”永远不会被HTML5插件覆盖(随iframe插件自动包含)。
这个错误吗?或者我做错了什么?
感谢您的帮助!
答案 0 :(得分:4)
总之;使用新的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加载器返回的类是,并且总是dojox.form.UploaderOrg,并且不知道扩展插件。
更改为以下内容:
var up = new dojox.form.Uploader({
label: 'Pick files',
multiple: true,
url: '/echo/json/'
}).placeAt(form);
确保您不设置djConfig.publishRequireResult = false