< -- 上传文件的表单 -- >
< form id = " uploadform" action = " /order/create" method = " post" enctype = " multipart/form-data" style =" display : none" >
< input type = " file" name = " file" id = " selectFile" multiple onchange = " fileupload()" />
</ form>
< -- 上传文件按钮 -- >
< button type = " button" id = " uploadButton" class = " btn btn-warning handleButton" onclick = " selectFile()" > 上传附件</ button>
var files= new Array ( ) ;
function selectFile ( ) {
$ ( "#selectFile" ) . click ( ) ;
}
function fileupload ( ) {
var form = document. getElementById ( "uploadform" ) ;
var formData = new FormData ( form) ;
uploadFile ( formData, "/order/uploadFile" , uploadCallback) ;
}
function uploadCallback ( result) {
var fileName = result. data[ 0 ] ;
var fielPath = result. data[ 1 ] ;
var file= { "name" : fileName, "downloadPath" : fielPath} ;
files. push ( file) ;
$ ( "#File_table" ) . bootstrapTable ( 'refresh' ) ;
$ ( "#item_File_table" ) . bootstrapTable ( 'refresh' ) ;
}
function ajaxGetFileRequest ( params) {
if ( files != null ) {
params. success ( {
total: files. length,
rows: files
} ) ;
}
}
function fileFormatter ( value, row, index) {
return [
'<button οnclick="delArrayByindex(\'' + index + '\')" class="btn btn-info btn-sm rightSize detailBtn" type="button">删除</button> ' ,
] . join ( '' ) ;
}
function delArrayByindex ( index) {
console. log ( index) ;
files. pop ( index) ;
$ ( "#File_table" ) . bootstrapTable ( 'refresh' ) ;
}