Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否可以使用extjs 5在文件上载窗口中选择多个文件?_Javascript_Html_Extjs - Fatal编程技术网

Javascript 是否可以使用extjs 5在文件上载窗口中选择多个文件?

Javascript 是否可以使用extjs 5在文件上载窗口中选择多个文件?,javascript,html,extjs,Javascript,Html,Extjs,是否可以使用extjs 5在文件上载窗口中选择多个文件?只需添加属性multiple:'',如下所示: var fileUploadButton = new Ext.create('Ext.form.field.File', { buttonOnly: true, hideLabel: true, buttonText: 'Upload Files...', fileInputAttributes: { ac

是否可以使用extjs 5在文件上载窗口中选择多个文件?

只需添加属性
multiple:''
,如下所示:

var fileUploadButton = new Ext.create('Ext.form.field.File', {
        buttonOnly: true,
        hideLabel: true,
        buttonText: 'Upload Files...',
        fileInputAttributes: {
            accept: 'application/xml',
            multiple: ''
        });
Ext.define('Ext.form.field.MyFile', {
    extend: 'Ext.form.field.File',
    alias: 'widget.multiplefileuploadfield',

    multiple: true,

    afterRender: function(){
        var me = this;

        me.callParent(arguments);

        if(me.multiple){
            me.fileInputEl.set({
                multiple:'multiple',
                name: me.name ? me.name + '[]' : 'files[]'
            });
        }
    }
});

Ext.define('Ext.form.field.FileButtonOverride', {
    override: 'Ext.form.field.FileButton',

    fireChange: function(e){
        var inp = this.fileInputEl.dom;

        if(!inp.files || !window.FileReader || !inp.files.length){
            this.fireEvent('change', this, e, inp.value);
            return;
        }

        var arrValues = [];
        for (var i = 0; i < inp.files.length; ++i) {
            arrValues.push(inp.files.item(i).name);
        }

        this.fireEvent('change', this, e, arrValues.join(', '));
    }
});

如果要显示文件名,可以这样做:

var fileUploadButton = new Ext.create('Ext.form.field.File', {
        buttonOnly: true,
        hideLabel: true,
        buttonText: 'Upload Files...',
        fileInputAttributes: {
            accept: 'application/xml',
            multiple: ''
        });
Ext.define('Ext.form.field.MyFile', {
    extend: 'Ext.form.field.File',
    alias: 'widget.multiplefileuploadfield',

    multiple: true,

    afterRender: function(){
        var me = this;

        me.callParent(arguments);

        if(me.multiple){
            me.fileInputEl.set({
                multiple:'multiple',
                name: me.name ? me.name + '[]' : 'files[]'
            });
        }
    }
});

Ext.define('Ext.form.field.FileButtonOverride', {
    override: 'Ext.form.field.FileButton',

    fireChange: function(e){
        var inp = this.fileInputEl.dom;

        if(!inp.files || !window.FileReader || !inp.files.length){
            this.fireEvent('change', this, e, inp.value);
            return;
        }

        var arrValues = [];
        for (var i = 0; i < inp.files.length; ++i) {
            arrValues.push(inp.files.item(i).name);
        }

        this.fireEvent('change', this, e, arrValues.join(', '));
    }
});
Ext.define('Ext.form.field.MyFile'{
扩展:“Ext.form.field.File”,
别名:“widget.multiplefileuploadfield”,
多重:对,
afterRender:function(){
var me=这个;
me.callParent(参数);
如果(me.multiple){
me.fileInputEl.set({
多重:'多重',
name:me.name?me.name+'[]':'文件[]'
});
}
}
});
Ext.define('Ext.form.field.FileButtonOverride'{
重写:“Ext.form.field.FileButton”,
fireChange:功能(e){
var inp=this.fileInputEl.dom;
如果(!inp.files | | |!window.FileReader | |!inp.files.length){
this.firevent('change',this,e,inp.value);
返回;
}
var值=[];
对于(变量i=0;i
我这样做了:

        xtype: 'filefield',
        buttonOnly: true,
        listeners: {
            change: function (view, value, eOpts) {
                //  alert(value);
                var parent = this.up('form');
                parent.onFileChange(view, value, eOpts);
            },
            render: function () {
                this.fileInputEl.set({ multiple: true });
            }

我不同意投票结束。OP不是询问使用哪种工具的建议,而是询问如何配置特定工具。不起作用。仍然只能选择单个文件。(向下投票原因)尝试删除浏览器的缓存,有时缓存会保存在浏览器中,并且在删除之前不会应用更改。您可以评论您的解决方案吗?确实需要使用函数fireChange将此文件ext/src/form/field/FileButton.js破解,以通过“,”将文件数组传递给字符串联接