Fix multiple upload

This commit is contained in:
afc163 2015-09-08 17:26:32 +08:00
parent 1056af34a7
commit f229f86a75
3 changed files with 45 additions and 6 deletions

View File

@ -14,6 +14,7 @@
* 新增 `fileList``defaultFileList` 属性,以满足更多的自定义功能,具体见演示。
* 设置 fileList 数组项的 url 属性可以作为链接展示在文件列表中方便下载。
* 移除内建的上传成功或失败的信息提示,业务可自行实现。
* 修正多文件选择上传时文件列表只展示一个文件的问题。
### Table

View File

@ -0,0 +1,31 @@
# 多文件选择
- order: 5
按住 ctrl 可选择多个文件,`ie10+` 支持。
---
````jsx
var Upload = antd.Upload;
var message = antd.message;
var props = {
action: '/upload.do',
multiple: true,
onChange(info) {
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList);
}
}
};
React.render(
<Upload {...props}>
<button type="button" className="ant-btn ant-btn-ghost">
<i className="anticon anticon-upload"></i> 点击上传
</button>
</Upload>
, document.getElementById('components-upload-demo-multiple'));
````

View File

@ -15,12 +15,10 @@ const AntUpload = React.createClass({
};
},
onStart(file) {
let nextFileList = this.state.fileList.concat();
file.status = 'uploading';
nextFileList.push(file);
this.onChange({
file: file,
fileList: nextFileList
add: true
});
},
removeFile(file) {
@ -76,9 +74,18 @@ const AntUpload = React.createClass({
// 1. fileList
// 2. info.event fileList
if (!('fileList' in this.props) && !info.event) {
this.setState({
fileList: info.fileList
});
// 使 multiple setState
if (info.add) {
this.setState((prevState) => {
return {
fileList: prevState.fileList.concat(info.file)
};
});
} else {
this.setState({
fileList: info.fileList
});
}
}
this.props.onChange(info);
},