今天做项目做了个上传的功能,不过遇到好多问题,先在这做个笔记。。。。
先引入
<link rel="stylesheet" type="text/css" href="<%=path %>/css/ext-all.css" />
<!-- GC -->
<!-- LIBS -->
<script type="text/javascript" src="<%=path %>/js/ext-base.js"></script>
<!-- ENDLIBS -->
<script type="text/javascript" src="<%=path %>/js/ext-all.js"></script>
<script type="text/javascript" src="<%=path %>/js/ext-lang-zh_CN.js"></script>
<script type="text/javascript" src="<%=path %>/js/UploadDialog/Ext.ux.UploadDialog.js"></script>
<script type="text/javascript" src="<%=path %>/js/UploadDialog/Ext.ux.UploadDialog.packed.js"></script>
Ext代码:
/**
* 文件上传
*/
function insertImages()
{
var editId=Ext.getCmp('queId').getValue();
//alert('../files.do?method=addFile&type=ntc&tmpId='+useId+'&isupdate='+isupdate+'&editId='+editId);
dialog = new Ext.ux.UploadDialog.Dialog({
title: '文件上传',
url:paths+'/files.do?method=addFile&type=que&tmpId='+useId+'&isupdate='+isupdate+'&editId='+editId,
width : 450,
height : 300,
minWidth : 450,
minHeight : 300,
draggable : true,
resizable : true,
//autoCreate: true,
constraintoviewport: true,
permitted_extensions:['ZIP','zip','DOC','doc','XLS','xls','TXT','txt','RAR','rar','JPG','jpg','GIF','gif','PNG','png'],
modal: true,
//post_var_name: 'mms',
post_var_name: 'upload',
reset_on_hide: false,
allow_close_on_upload: true, //关闭上传窗口是否仍然上传文件
upload_autostart: true
});
dialog.show();//'show-button'
dialog.on('uploadsuccess', onUploadSuccess);
}
function onUploadSuccess(dialog, filename, resp_data, record){
var queId='';
if(isupdate==1)
queId=useId;
if(isupdate==2)
queId=Ext.getCmp('queId').getValue();
fileDs.load({
params: {
findId: queId,
type:'que',
isupdate:isupdate
}
});
}
Ext.ux.UploadDialog中的其它事件函数[转载自http://wayfoon.iteye.com/blog/432541]
* filetest - fires before file is added into the queue, parameters:
dialog - reference to dialog
filename - file name
If handler returns false then file will not be queued.
* fileadd - fires when file is added into the queue, parameters:
dialog - reference to dialog
filename - file name
* fileremove - fires when file is removed from the queue, parameters:
dialog - reference to dialog
filename - file name
record - file record
* resetqueue - fires when upload queue is resetted, parameters:
dialog - reference to dialog
* beforefileuploadstart - fires when file as about to start uploading:
dialog - reference to dialog
filename - uploaded file name
record - file record
If handler returns false then file upload will be canceled.
* fileuploadstart - fires when file has started uploading:
dialog - reference to dialog
filename - uploaded file name
record - file record
* uploadsuccess - fires when file is successfuly uploaded, parameters:
dialog - reference to dialog
filename - uploaded file name
data - js-object builded from json-data returned from upload handler response.
record - file record
* uploaderror - fires when file upload error occured, parameters:
dialog - reference to dialog
filename - uploaded file name
data - js-object builded from json-data returned from upload handler response.
record - file record
* uploadfailed - fires when file upload failed, parameters:
dialog - reference to dialog
filename - failed file name
record - file record
* uploadcanceled - fires when file upload canceled, parameters:
dialog - reference to dialog
filename - failed file name
record - file record
* uploadstart - fires when upload process starts, parameters:
dialog - reference to dialog
* uploadstop - fires when upload process stops, parameters:
dialog - reference to dialog
* uploadcomplete - fires when upload process complete (no files to upload left), parameters:
dialog - reference to dialog