您可以使用FileReader 对象来读取文件。下面是执行此操作的示例代码。
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
fullscreen: true,
items: [{
xtype: 'fieldset',
title: 'My Uploader',
items: [
{
xtype: 'filefield',
label: "MyPhoto:",
name: 'photo'
}, {
xtype: 'button',
text: 'Get File',
handler: function(){
let file = this.up().down('filefield').el.down('input[type=file]').dom.files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
let result = e.target.result;
//process upload with result
alert(result);
};
})(file);
reader.readAsBinaryString(file);
}
}
]
}]
});
}
});
你可以找到工作小提琴here
您也可以使用form.submit() 方法提交表单。
var form = this.up('form').getForm();
if(form.isValid()) {
form.submit({
url: 'photo-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file +
'" has been uploaded.');
}
});
}
你可以找到这个例子here