2017-03-01 53 views
1

我试图将.map中的一个元素移到onClick函数,以便我可以将它传递给redux,但我不知道如何继续。这是我的代码如何将数据从.map传输到带有onClick的href元素的功能

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) 
} 

感谢

回答

2

试试这个....

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); 
} 
+0

谢谢,这个作品 – OunknownO

+0

请接受,如果适合你 – Zinc

+0

对不起,我不能接受它立即 – OunknownO

相关问题