小编Pra*_*JaL的帖子

我正在尝试使用 rowEvents 来触发 react-bootstrap-table-2 中的操作,但 onClick 中的“this”未定义。有任何想法吗?

这是代码块:

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 }
            /> …
Run Code Online (Sandbox Code Playgroud)

onclick this reactjs react-bootstrap-table

6
推荐指数
1
解决办法
475
查看次数

标签 统计

onclick ×1

react-bootstrap-table ×1

reactjs ×1

this ×1