我有一个类似如下反应的组分
UploadView.js
getInitialState: function() {
return {
file: null,
mappingType: null
}
},
setMappingType: function(){
this.setState({
mappingType: this.state.mappingType
});
},
render: function(){
<FileDropdown mappingType={this.setMappingType}/>
<FileUpload mappingType={this.state.mappingType}/>
}
FileDropDown是一个子组件向用户呈现下拉功能和外观作为父组件之间的交互以下
FileDropDown.js
pickedOption: function(event){
var option = event.nativeEvent.target.selectedIndex;
var value = event.nativeEvent.target[option].text;
this.props.mappingType = value;
},
render: function(){
return (
<select name="typeoptions" id="mappingTypes" onChange={this.pickedOption}>.....</select>
)
}
我想明白了,如果以正确的方式上面更新状态,并会更新/设置在FileDropDown值this.props.mappinType将更新后的值设定在状态mappingType父UploadView
感谢@Prutser,对于额外的小费 – RRP
欢迎你,很乐意帮助! – Prutser