EXT.JS2.2表单上传文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37279783/article/details/83866987
var uploadFile = new Ext.form.TextField({
            fieldLabel: '上传文件',
            id:'file',
            name: 'uploadFile',
            height : 25,
            width : 860,
            blankText: '请上传文件',
            itemCls:'float-left',
            clearCls : 'allow-float',
            inputType: 'file',
            validator:function (v) {
                if(!/\.xls$/.test(v)){
                    return false;
                }
                hasFile = v;
                return true;
            }
        });

        var form_q = new Ext.form.FormPanel({
            title : '批量导入',
            region : 'center',
            frame : true,
            method : 'post',
            labelWidth:70,
            autoHeight : true,
            autoScroll : true,
            layout: 'column',
            fileUpload: true,
            items : [
                {
                    columnWidth:.95,
                    layout: 'form',
                    items: [comboBox,uploadFile]
                }
            ],
            buttons: [{
                id:'btn',
                text: "上传",
                iconCls: "btn_ico_save",
                handler: saveHandler,
            }]
        });

        function saveHandler(){
            if(!dataPath){
                Ext.MessageBox.alert('错误',"请选择一个挂载路径!");
                return false;
            }
            if(!hasFile){
                Ext.MessageBox.alert('错误',"请选择上传文件!");
                return false;
            }
            form_q.getForm().doAction('submit',{
                method:"post",
                url:'tHarvestTableSdep.do?invoke=upload&dataPath='+dataPath,
                success: function(f, a){
                    Ext.MessageBox.alert('提示',a.result.msg);
                    Ext.getCmp('btn').setVisible (false);
                },
                failure: function(f, a){
                    Ext.MessageBox.alert('错误',a.result.msg);
                }
            });
        }

        var viewport = new Ext.Viewport({
            layout : 'border',
            border: false,
            items : [form_q]
        });

猜你喜欢

转载自blog.csdn.net/qq_37279783/article/details/83866987