这是代码块:
const expandRow = {
renderer: row => (
<div>
<BootstrapTable
keyField='id'
data={ row.data }
columns={ columns1 }
/>
</div>
)
};
export default class MyPage extends Component {
constructor(props, context) {
super(props, context);
}
componentDidMount() {
this.props.actions.fetchData(). // fetches in this.props.data
}
rowEvents = {
onClick: (e, row, rowIndex) => {
this.props.actions.fetchHistory(row.Id). /* this is undefined */
}
}
render() {
return (
<BootstrapTable
keyField='Id'
data={ this.props.data }
columns={ columns }
striped
rowEvents={ this.rowEvents }
expandRow={ expandRow }
/>
)
}
}
我想要做的是对于点击的每一行,我想通过触发一个 Action 来获取数据。我在这里理解“这个”的上下文可能是错误的。有任何想法吗?
最佳答案
rowEvents 不是函数而是常量,尝试用 const 定义
const rowEvents = {
onClick: (e, row, rowIndex) => {
this.props.actions.fetchHistory(row.Id). /* this is undefined */
}
}
关于reactjs - 我正在尝试使用 rowEvents 触发 react-bootstrap-table-2 中的操作,但 onClick 中的 'this' 未定义。有任何想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63080891/