如何使用 onClick 将数据从 .map 传输到 href 元素的函数

How to transfer data from .map to function from href element with onClick

我正在尝试将一个元素从 .map 移动到 onClick 函数,以便我可以将它传递给 redux,但我不确定如何继续。这是我的代码

const Lists = lists.map((list, index) =>
    <li key={index}> {list.name} <a href="#" onClick={this.listInfo.bind(this)}>Learn More</a> </li> );

这是函数

listInfo(event){
  event.preventDefault();
  var el = list.name //this is where I want to save that value;
  console.log(el)
}

提前致谢

试试这个....

const Lists = lists.map((list, index) =>
<li key={index}> {list.name} <a href="#" onClick={(e) => this.listInfo(e, list.name)}>Learn More</a> </li> );

然后把你的函数改成这个...

listInfo(event, listName){
//.....
console.log(listName);
}