zoukankan      html  css  js  c++  java
  • react 事件传参

    在开发react项目时,点击事件需要传参,就有了以下的写法:

    <Button type="primary" size="small" onClick={this.showModal.bind(this, lists[i])}>编辑</Button>
    <Button type="primary" size="small" onClick={this.showDelete.bind(this, lists[i])}>删除</Button>

    运行时报错:

    但,奇怪的是,我两个button都用到了,可是只有一个报错,那我猜测可能是showModal或者showDelete没定义,一查,确实如此。

    另: 附带es6中react的绑定办法:

    <Button type="primary" size="small" onClick={e => this.showModal(lists[i])}>编辑</Button>
    <Button type="primary" size="small" onClick={e => this.showDelete(lists[i])}>删除</Button>

    即,箭头函数

  • 相关阅读:
    UIautomator Python测试
    selenium提供了三种模式的断言:assert,verify,waitfor
    编译标志
    模块级函数
    执行匹配
    反斜杠
    正则表达式
    重复
    字符匹配
    贪婪 vs 不贪婪
  • 原文地址:https://www.cnblogs.com/wylj/p/9407190.html
Copyright © 2011-2022 走看看