从语义 ui 反应中获取按钮值
Get the button value from semantic ui react
我是新手 React.Currently 我正面临这个问题。
这是我的代码
handleClick(e) {
console.log('Click happened'+" "+ e.target.value);//getting UNDEFINED here
}
在下面的代码中,locationArr 包含很多位置
{ locationArr.map((location) => {
console.log(location); //It prints all the locations here NO PROBLEM
if (location !== ' ') {
return (
<div className ="ui stackable four column grid">
<div className="column centered">
</div>
<div className="column">
</div>
<div className="column centered">
<Button size='huge' primary value='{location}' as={Link}
to="/location" onClick={this.handleClick.bind(this)} >
{location} // ABLE TO GET LOCATION NAMES here
</Button>
现在我的问题是我想从 handleClick 函数中的按钮访问位置的值,我还需要将它传递给另一个 component.Anyone 请建议我如何实现这个?
改变
onClick={this.handleClick.bind(this)}
至
onClick={this.handleClick.bind(location)}
工作Demo
演示解决了您的两个问题。
我是新手 React.Currently 我正面临这个问题。
这是我的代码
handleClick(e) {
console.log('Click happened'+" "+ e.target.value);//getting UNDEFINED here
}
在下面的代码中,locationArr 包含很多位置
{ locationArr.map((location) => {
console.log(location); //It prints all the locations here NO PROBLEM
if (location !== ' ') {
return (
<div className ="ui stackable four column grid">
<div className="column centered">
</div>
<div className="column">
</div>
<div className="column centered">
<Button size='huge' primary value='{location}' as={Link}
to="/location" onClick={this.handleClick.bind(this)} >
{location} // ABLE TO GET LOCATION NAMES here
</Button>
现在我的问题是我想从 handleClick 函数中的按钮访问位置的值,我还需要将它传递给另一个 component.Anyone 请建议我如何实现这个?
改变
onClick={this.handleClick.bind(this)}
至
onClick={this.handleClick.bind(location)}
工作Demo
演示解决了您的两个问题。