[英]Passing Array Index to onClick Function ReactJS
I want to pass the data from an array to onClick function using some value as reference maybe using index我想使用一些值作为参考将数据从数组传递给 onClick 函数,也许使用索引
here is the code这是代码
tempEle.push(
<tr key={set.product[i].id}>
<td className="body-sticky">
<div>
<strong>
{set.product[i] && set.product[i].name
? <a href= {set.product[i].id} onClick = {(e, id)=>alert(e.preventDefault(),id)} >
{set.product[i].name}
</a>
: '-'}
</strong>
</div>
Just change your onClick attribute to blank arrow method.只需将您的 onClick 属性更改为空白箭头方法即可。 This should work.
这应该有效。
{set.product[i] && set.product[i].name
? <a href= {set.product[i].id} onClick = {()=>alert(set.product[i].id)} >
{set.product[i].name}
This will create a new method which will execute when you click on the link.这将创建一个新方法,当您单击链接时将执行该方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.