Ext.create('Ext.form.Panel', {
title: '上传图片预览',
bodyPadding: 5,
width: 350,
items: [{
xtype: 'filefield',
id: 'upload',
fieldLabel: "产品图片",
emptyText : '选择文件存放路径',
buttonText:'浏览...',
width: '100%',
name: 'photo',
listeners : {
'render' : function() {
Ext.getCmp('upload').on('change',function(field, newValue, oldValue) {
var file = field.fileInputEl.dom.files.item(0);
var fileReader = new FileReader('file://'+newValue);
fileReader.readAsDataURL(file);
fileReader.onload=function(e){
Ext.getCmp('imageId').setSrc(e.target.result);
}
});
}
}
},{
xtype: 'image',
id: 'imageId',
src: 'http://www.sencha.com/img/20110215-feat-perf.png',
width: 184,
height: 90
}]
});