开发者问题收集

未捕获的类型错误:无法读取未定义的属性(读取‘start_time’)

2022-02-02
1360

当我更新上一个间隔的最后结束时间时遇到此错误,尽管它更新了我的状态但不显示在表中

在此处输入图像描述

const onEdit = (oldValue, newValue, row, column) => {
    const oldRows = props.row;
    console.log("BHai", props.row.length - 1);
    if (column.dataField === "end_time") {
      if (newValue < oldRows[row.interval + 1].start_time) {
        oldRows[row.interval][column.dataField] = newValue;
        const startTime = parseInt(row.start_time);
        const endTime = parseInt(row.end_time);
        props.onIntervalUpdate([startTime, endTime], row.interval);
        console.log("BHai1");
      } else if (oldRows[row.interval].interval === props.row.length - 1) {
        oldRows[row.interval][column.dataField] = newValue;
        const startTime = parseInt(row.start_time);
        const endTime = parseInt(row.end_time);
        props.onIntervalUpdate([startTime, endTime], row.interval);
        console.log("BHai2");
      } else {
        oldRows[row.interval][column.dataField] = oldValue;
        const startTime = parseInt(row.start_time);
        const endTime = parseInt(row.end_time);
        props.onIntervalUpdate([startTime, endTime], row.interval);
        console.log("BHai3");
      }
    }

在此处输入图像描述

2个回答

考虑在解构过程中添加 可选链接 (?.) ,例如:

newValue < oldRows[row.interval + 1]?.start_time)

const startTime = parseInt(row?.start_time);
NeERAJ TK
2022-02-02

像这样弄清楚了,

if (
        oldRows[row.interval].interval === props.row.length - 1 &&
        oldRows[row.interval].start_time
      )

对我来说很好用

Fashad Ahmed
2022-02-02