2016-03-01 20 views
7

L'evento click funziona correttamente, ma l'evento onmouseover non funziona.onmouseover non funziona con React.js

ProfImage = React.createClass({ 

    getInitialState: function() { 
     return { showIcons: false }; 
    }, 

    onClick: function() { 

     if(this.state.showIcons == true) { 
      this.setState({ showIcons: false }); 
     } 
     else { 
      this.setState({ showIcons: true }); 
     } 
    }, 

    onHover: function() { 
     this.setState({ showIcons: true }); 
    }, 

    render: function() { 

     return (
      <div> 
      <span className="major"> 
       <img src="/images/profile-pic.png" height="100" onClick={this.onClick} onmouseover={this.onHover} /> 
      </span> 


      { this.state.showIcons ? <SocialIcons /> : null } 
      </div> 

     ); 
    } 

}); 

risposta

10

È necessario inserire in maiuscolo alcune lettere.

<img src="/images/profile-pic.png" height="100" onClick={this.onClick} onMouseOver={this.onHover} /> 
11

Entrambe le risposte sopra sono corrette, ma è necessario associare questi metodi anche al contesto di classe!

<img src="/images/profile-pic.png" height="100" onClick={this.onClick.bind(this)} onMouseOver={this.onHover.bind(this)} /> 
+1

'onMouseOver = {this.onHover.bind (this, 'value')}' –