为了账号安全,请及时绑定邮箱和手机立即绑定

如何将事件和触发的函数当作参数传递,可以使用jsx语法

如何将事件和触发的函数当作参数传递,可以使用jsx语法

慕婉清6462132 2019-02-11 15:18:09
page1columns = [{    title: '操作', dataIndex: 'action',    fixed: 'right',    width: 76,    render: [        { title: '编辑', icon: 'edit', span: 12, onClick: 'this.showEdit.bind(this, record)', },        { title: '删除', icon: 'delete', span: 12, onClick: 'this.delectItem.bind(this, record)', },    ],},,,,]page2handleColumns = (columns) => {    columns.forEach((item, index) => {        if (item.dataIndex == 'action') {            item['render'] = (text, record) => (                <Row type="flex" justify="space-between" align="middle" gutter={8} style={{ width: item.width }}>                    {item.other.map((item, index) => {                        return <Col key={index} span={item.span}><Tooltip title={item.title}><Button shape="circle" icon={item.icon} /></Tooltip></Col>                    })}                </Row>            )        }    })    return columns}<Table    columns={handleColumns(columns)}/>如果换成jsx语法,因为不在一个页面,函数会在page1执行,因为this指向的是page1
查看完整描述

2 回答

?
炎炎设计

TA贡献1808条经验 获得超4个赞

不要用 bind 或箭头函数不就好了。onClick = {this.showEdit}

还有,你最上面 page1里的,onClick: 'this.showEdit.bind(this, record)' 是错的,首先onclick 的值是个字符串,根本不是方法,其次,bind 用法也错误。


查看完整回答
反对 回复 2019-02-27
  • 2 回答
  • 0 关注
  • 652 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号