我有以下反应组件Timepicker:
/usr/local/lib/python2.7/dist-packages/django/template/utils.py:37:
RemovedInDjango110Warning: You haven't defined a TEMPLATES setting. You must
do so before upgrading to Django 1.10. Otherwise Django will be unable to load
templates. "unable to load templates.", RemovedInDjango110Warning)
SingleTask使用TimePicker:
export default class TimePicker extends Component{
render(){
return(
<div>
<input id={this.props.nameID} type="text"></input>
</div>);
}
}
如何从SingleTask访问TimePicker中的输入值?
答案 0 :(得分:1)
您可以通过两种方式解决此问题:
:
export default class SingleTask extends Component{
yourFunction(){
var selectedTime = React.findDOMNode(this.refs.timePickerComp).querySelector('input').value;
}
render(){
....
<TimePicker ref="timePickerComp" nameID="time" />
.....
}
}
TimePicker:
export default class TimePicker extends Component{
function getSelectedTime(){
return document.getElementById(this.props.nameID).value;
}
render(){
return(
<div>
<input id={this.props.nameID} type="text"></input>
</div>);
}
}
SingleTask:
export default class SingleTask extends Component{
yourFunctionWhereYouNeedTime(){
var timeSelected = this.refs.timePickerComp.getSelectedTime(); // here you'll access the child component data.
}
render(){
....
<TimePicker ref="timePickerComp" nameID="time" />
.....
}
}