javascript - ReactJS - setState to multiple elements -
i trying set state (actiu) of multiple components false, referring them via class. how can achieve when click label row, actiu state of elements in row turn false? here's component tree:
there blade templating syntax generates each row of labels
var respostesbox = react.createclass({ render: function() { return ( <div classname="form-group"> <?php $zenbatu = 0; ?> @foreach($preguntes $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') );
thanks in advance help!
i suggest should create component row parent of labelresp component , children of resposterbox. set state , handleclick in resposterbox component.
in order communicate wirh rows, can pass index of each row handleclick. maybe doc can
Comments
Post a Comment