我有一個類似如下反應的組分
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