javascript - Get props from child form component , ReactJS -


i new react.

i writing component arrayinput contains multiple(based on state) input box.

and arrayinput need handle each input box's onchange event.

i hope specific props/attribute (in case , "index") on these dramatically generated input box

i search many posts , docs can't find correct way.

i know can use this.ref[inputboxref](react 14+) actual dom node , find has no "attribute" or "data" when using $(domnode).attr('index') or $(domnode).data('index').

    window.arrayinput = react.createclass({              ......other methods              handlechange:function(ref,event){                 var dominputbox = this.refs[ref];                 //trying index attribute of input              }              render:function(){                 var self = this;                 return (                     <div classname="input-wrapper"  >                                                        <label>                             <div>{this.props.label}</div>                              {                                 this.state.value.map(function(e,i){                                     return  (                                                                    <input type="text"                                             ref={"arraybox"+i}                                             key={"arraybox"+i}                                             index={i} //custom attribute                                             value={e}                                             onchange={self.handlechange.bind(self,"arraybox"+i)}                                         />                                     )                                 })                             }                          </label>                     </div>                 )             }     }); 

you can use event.target. try event.target.index.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -