<Parent> /* event to fetch all refs value and submit */
<Child>
<stateless function />/*this is all the refs sittin*/
</Child>
</Parent>
我不知道父母如何从孩子那里获得所有参考?提前致谢
我知道可能为时已晚,而你已经知道答案了。您需要的是“参考”,即对孩子的参考。阅读本文:将 DOM Refs 暴露给父组件
像这样的东西:
class Parent extends React.Component {
render() {
return (
<div>
// this line will create a reference to the input text,
// inside the Child Component
// for example, if you want to get the value
// you can access `this.input.value`
<Child inputRef={(refToChild) => this.input = refToChild} />
</div>
)
}
}
class Child extends React Component {
render() {
return (
<form>
// this line will call the Parent's function,
// creating a reference to the input text.
<input type="text" ref={props.inputRef} />
</form>
)
}
}