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)}
/>
如果换成jsx语法,因为不在一个页面,函数会在page1执行,因为this指向的是page1
用这种方式解决了问题