简体   繁体   中英

onClick event in map function of ReactJS not firing

I think I am missing something very simple here. My onClick event in map function isnt firing. I put a test hello function to test it out and it still doesnt seem to work. Any help will be appreciated.

window.PredictionContainer = React.createClass({
   mixins:[PredictionWatchMixin(predictionItems)],
   **hello: function(){
     alert("aasd");
     },**
     render:function(){
        var self = this;
        var matches = this.state.matches.map(function(match,i)
        {
          return (
          <div key={i} **onClick={self.hello}** className="post box padd">Some dummy text here </div>
          )
        });
        return (
          <div><PredictionTabs  tournament_id={this.props.tournament_id} onClick={this.updateEvent}/> {matches}  </div>
           );  
     }
);

I met the same problem and solved it like this:

var matches = this.state.matches.map(function(match,i)
        {
          return (
          <div key={i} **onClick={self.hello}** className="post box padd">Some dummy text here </div>
          )
        }.bind(this));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM