zoukankan      html  css  js  c++  java
  • react中使用map时onClick事件失效

    分享一些踩过的坑

    react中使用map时onClick事件失效

        <span>
          {
            count.map(
              (item,index)=>{
                return <span style={{paddingRight:2,cursor:'pointer'}} key={index} onClick={handleEditCount(item[1],item[2])}>{item[0]}<Icon type="edit" /></span>
              }
            )
          }
        </span>
    

    这样是真的失效吗

    不,只是不会用而已

    其实把函数改成箭头函数就能用啦

        <span>
          {
            count.map(
              (item,index)=>{
                return <span style={{paddingRight:2,cursor:'pointer'}} key={index} onClick={() => handleEditCount(item[1],item[2])}>{item[0]}<Icon type="edit" /></span>
              }
            )
          }
        </span>
    

    顺便说一下 .bind相当于箭头函数

  • 相关阅读:
    DFS-B
    DFS/BFS-A
    DFS-回溯与剪枝-C
    BFS-八数码问题与状态图搜索
    PTA-1003 我要通过!
    二分-G
    二分-F
    二分-E
    二分-D
    二分-C
  • 原文地址:https://www.cnblogs.com/piaobodewu/p/10232685.html
Copyright © 2011-2022 走看看