简体   繁体   中英

Cannot read property 'replace ' of undefined

Here I'm trying to get the current path, but also have problem and says that Cannot read property 'replace' of undefined . Who could help me to resolve this problem ?

handleClick= (event: SyntheticMouseEvent<HTMLButtonElement>) => {
        const { workflowPath: _workflowPath } = this.props;

        let workflowPath = _workflowPath;

        Object.keys(this.props.row._original).forEach((key) => {
            workflowPath = workflowPath.replace(`{${key}`, this.props.row._original[key]);
        });

        this.props.startFlow(workflowPath);
        this.setState({ loading: true });
    };

Also this handleClick is in component which is called Cell .

Header: 'Status',
accessor: 'status',
label: 'Change status',
type: 'workflow',
workflowPath: 'process/task/change_status',
icon: <Launch />,
items: [
    {
        label: 'New',
    },
    {
        label: 'In progress',
    },
    {
        label: 'Rejected',
    },
    {
        label: 'Complete',
    },
],
Cell: WorkflowColumn,

I believe it should be:

workflowPath && workflowPath.length &&
  Object.keys(this.props.row._original).forEach((key) => {
  ...

This will check that workflowPath actually has something in it. If it's null this leads to the error you have been experiencing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM