所以,在反应过来,我们知道我们可以有孩子通过这样的回调与家长沟通:如何通过祖父母组件中的“子女”动态定义父母/子女组成部分之间的通信?
Child = React.createClass({
render() {
return (
<div>
<button onClick={this.props.onAction.bind(null, this.props.name)}>Child button</button>
</div>
)
}
});
Parent = React.createClass({
handleChildAction(name) {
alert(`Child button ${name} clicked`);
},
render() {
return (
<div>
<Child name="robot1" onAction={this.handleChildAction} />
</div>
)
}
});
但我不清楚如何可以有这个父母/子女之间的双向通信一种格式:
Container = React.createClass({
render() {
return (
<Parent>
<Child name="robot1" />
<Child name="robot2" />
</Parent>
)
}
});
我怎样才能得到Parent
向下发送信息给孩子,并有Child
发送信息吗?
http://facebook.github.io/react/docs/two-way-binding-helpers.html –
不错!这是通常回调结构的一个很好的捷径,但它并不能解释如何在上面的场景#2中让'Parent'与孩子交谈。 – ffxsam