我试图将多个组件的状态(actiu)设置为 false,通过类引用它们。当我从一行中单击一个标签时,如何实现这一点,该行中所有元素的活动状态都变为 false?这是我的组件树:
有一些 Blade 模板语法会生成每一行标签
var RespostesBox = React.createClass({
render: function() {
return (
<div className="form-group">
<?php $zenbatu = 0; ?>
@foreach($preguntes as $p)
<div className="well">
{{ $p->preg }}
{{ $p->help }}
</div>
<?php $zenbatu++ ?>
<?php for($j = 0; $j <= 10; ++$j) { ?>
<LabelResp izena="resp{{ $zenbatu }}" balioa="{{ $j }}" />
<?php } ?>
@endforeach
</div>
);
}
});
var LabelResp = React.createClass({
getInitialState: function() {
return {actiu: false};
},
handleClick: function(event) {
//
this.setState({actiu: true})
},
render: function() {
return (
<label className={this.state.actiu ? "radio-inline amgrd actiu" :"radio-inline amgrd"} onClick={this.handleClick}>
<input type="radio" name={this.props.izena} value={this.props.balioa} className={this.props.izena} /> {this.props.balioa}
</label>
);
}
});
React.render(
<RespostesBox />,
document.getElementById('lespreguntes')
);
在此先感谢您的帮助!