Javascript 反应引导上的onClick事件

Javascript 反应引导上的onClick事件,javascript,reactjs,events,react-bootstrap,Javascript,Reactjs,Events,React Bootstrap,我试图学习的意思,我试图使一个简单的口袋妖怪发现 问题是,我对附加到组件的事件有问题 以下是主要观点: import React,{Component,PropTypes}来自'React'; 从'react redux'导入{connect}; 从“redux”导入{bindActionCreators}; /*导入组件*/ 从“./components/Search/Search”导入搜索; 从'react bootstrap'导入{Grid,Row,Col}; /*进口行动*/ 从“/P

我试图学习的意思,我试图使一个简单的口袋妖怪发现

问题是,我对附加到组件的事件有问题

以下是主要观点:

import React,{Component,PropTypes}来自'React';
从'react redux'导入{connect};
从“redux”导入{bindActionCreators};
/*导入组件*/
从“./components/Search/Search”导入搜索;
从'react bootstrap'导入{Grid,Row,Col};
/*进口行动*/
从“/PokedexActions”导入{fetchByName};
//导入样式
//从“/Pokedex.css”导入样式;
类Pokedex扩展组件{
handleFind=(名称)=>{
this.props.dispatch(fetchByName({name}));
};
render(){
返回(
);
}
}
常量mapStateToProps=(状态)=>{
返回{};
};
const mapDispatchToProps=(调度)=>{
返回{};
};
Pokedex.contextTypes={
路由器:React.PropTypes.object
};
导出默认连接(
MapStateTops,
mapDispatchToProps
)(Pokedex)
就像前面提到的,您应该使用
onChange={this.handleClick.bind(this)}
而不是
onChange={this.handleClick}

但是,您可以为类
Pokedex
添加构造函数以获得更高的可读性

export class Search extends Component {
  constructor(props, context) {
    super(props, context);
    
    this.handleClick = this.handleClick.bind(this);
  }
  
  // the rest of code...
}
正如前面提到的,您应该使用
onChange={this.handleClick.bind(this)}
而不是
onChange={this.handleClick}

但是,您可以为类
Pokedex
添加构造函数以获得更高的可读性

export class Search extends Component {
  constructor(props, context) {
    super(props, context);
    
    this.handleClick = this.handleClick.bind(this);
  }
  
  // the rest of code...
}

你是说handleClick()方法没有被解雇吗?试试
onClick={()=>this.handleClick()}
onChange={this.handleClick}应该是onChange={this.handleClick.bind(this)}@Ved是handleClick()method@RicardoACB控制台中是否有错误?是否意味着handleClick()方法未被激发?请尝试
onClick={()=>this.handleClick()}
onChange={this.handleClick}应该是onChange={this.handleClick.bind(this)}@Ved yes handleClick()method@RicardoACB控制台中是否有错误?