2016-04-29 162 views
0

我有一个附加到表中每个select元素的onChange事件的React组件。这些select元素也有select2的jquery库来处理它们。无论出于何种原因,该事件不触发(在控制台中没有错误其一):React - onChange事件在select2列表中未触发

import select2 from 'meteor/natestrauser:select2'; 

export default class MyComponent extends React.Component { 

    constructor(props) { 
     super(props); 
    } 

    executeSelectedOption(e){ 
     console.log("Worked!"); 
    } 

    componentDidUpdate(){ 
     $("select.js-example-placeholder-single").select2({ 
      minimumResultsForSearch: Infinity 
     }); 
    } 

    render() { 
    var results = this.props.data; 
    return (
     <div> 
      <table> 
       <thead> 
        <tr> 
         <th>Title</th> 
         <th></th> 
        </tr> 
       </thead> 
       <tbody> 
        {results.map(function(d, index) { 
         return (
          <tr key={d._id}> 
           <td>{d.title}</td> 
            <td> 
             <select onChange={this.executeSelectedOption.bind(this)} className="js-example-placeholder-single"> 
              <option value="">...</option> 
              <option value="1">Do this</option> 
              <option value="2">Do that</option> 
             </select> 
            </td> 
           </tr> 
          ) 
         }, this)} 
        </tbody> 
       </table> 
      </div> 
     ); 
    } 
} 

回答