mercredi 25 janvier 2017

add/remove elements to array with checkboks and reactjs

I have this code that inserts the ids of the checkboks into an array, but if I disable them, it does not remove them, i use update to react-addons-update any suggestions

     constructor(props) {
        super(props);
         this.state={
           keyGen:[]
         }
      }
      render(){  
         <form> 
            {this.renderElements()}
             <input type="submit" value="Save" />
        </form>
      renderElement(){
       return this.props.Elements.map((item, index)=>{
render(
        <Input name='list' type='checkbox' onClick={()=>this.updateStateList(item.id)} label='Add' className='listTour' />
       ) 
        })
        }

      updateStateList(value){
        this.setState(update(this.state, {keyGen: {$push:[value]}}))
        console.log(this.state.keyGen)
      }

thanks




Aucun commentaire:

Enregistrer un commentaire