samedi 24 juin 2017

How can I get the key from the event object when I handle the method In React?

The e.key is undefined when I click the DOM element; How can I fecth the key of the DOM?

Source code

constructor(props) {
    super(props);
    this.__handle = this.__handle.bind(this);
}

__handle(e){
    console.log(e);
    console.log(e.key);
}

render() {

    let that = this;
    let data = [1,2,3,4];
    let com = data.map(function(data,index){
        return <div key={index} onClick={that.__handle}>data</div>
    })

    return <div>
        {com}
    </div>;
}

The vision of React is ^15.6.1.

Thanks!




Aucun commentaire:

Enregistrer un commentaire