【发布时间】:2018-04-03 12:35:10
【问题描述】:
我遇到了这个奇怪的问题,我想不通。
我有一个按钮,点击后会出现一个文件窗口
当用户选择一个文件并单击确定时,我有this.setState({file}) 记录用户选择的文件。但它不起作用。
<div id="file-upload-submit-btn-container">
<Button id="choose-file-btn"
onClick={this.buttonClick.bind(this)}>
Choose file
</Button>
<input type="file" id="upload-input"
onChange={this.handleInputSelect.bind(this)}
onClick={(e) => e.target.value = null} // reset input file
multiple={false}/>
</div>
javascript
constructor() {
super()
this.state ={
url: "https://example.com:8303",
}
}
getFileUploader() {
return $(this.refs.dropzone).find("#upload-input")
}
buttonClick(e) {
e.preventDefault()
let $fileuploader = this.getFileUploader()
$fileuploader.trigger('click');
}
handleInputSelect(e) {
e.preventDefault()
let file = e.target.files[0]
this.setState({file}) <---- setState at here, but it is not getting recorded
console.log(file, this.state.file) <---file IS defined here but not this.state.file, why?
this.handleUpload()
}
【问题讨论】:
标签: reactjs