在Click ES6 React上获取关键索引 [英] Get Key Index on Click ES6 React

查看:274
本文介绍了在Click ES6 React上获取关键索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下组成部分

const list = (props) => {

  const handler = function(){

  };

  var listItems = props.items.map(function(item, index){
    return (
      <li key={index} onClick={ handler }>
        {item.text}
      </li>
    )
  });

  return (
    <div>
      <ul>
        {listItems}
      </ul>
    </div>
  )
}

点击时,我想获取被点击的li的索引.使用ES6并且没有绑定,我该怎么做?

On Click i'd like to get the index of the li clicked. Using ES6 and without binding how can i do this ?

推荐答案

使用箭头功能.

onClick={() => handler(index)}

这篇关于在Click ES6 React上获取关键索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆