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

page1


columns = [{

    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)', },

    ],

},,,,]

page2


handleColumns = (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)}

/>

https://img1.mukewang.com/5c763d4e000194b708000153.jpg

如果换成jsx语法,因为不在一个页面,函数会在page1执行,因为this指向的是page1

慕婉清6462132
浏览 653回答 2
2回答

炎炎设计

不要用&nbsp;bind&nbsp;或箭头函数不就好了。onClick = {this.showEdit}还有,你最上面 page1里的,onClick: 'this.showEdit.bind(this, record)'&nbsp;是错的,首先onclick 的值是个字符串,根本不是方法,其次,bind&nbsp;用法也错误。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript