所以,在反應過來,我們知道我們可以有孩子通過這樣的回調與家長溝通:如何通過祖父母組件中的「子女」動態定義父母/子女組成部分之間的通信?
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