【发布时间】:2025-12-11 13:55:01
【问题描述】:
我正在寻找一种让两个组件相互通信的方法。我只是想要它,以便在选中或取消选中 <InputCheckboxAll/> 时,它将选中或取消选中所有 <InputCheckbox/> 组件。
var InputCheckboxAll = React.createClass({
render: function () {
return (
<input type='checkbox' {...this.props}/>
)
}
})
var InputCheckbox = React.createClass({
render: function () {
return (
<input type='checkbox' {...this.props}/>
)
}
})
<InputCheckboxAll ref='masterCheckbox'/>
<InputCheckbox masterRef='masterCheckbox'/>
<InputCheckbox masterRef='masterCheckbox'/>
<InputCheckbox masterRef='masterCheckbox'/>
如何从 <InputCheckboxAll> 组件中选择 dom 上带有 masterCheckbox 的所有引用?
【问题讨论】:
标签: javascript reactjs components