gpt4 book ai didi

angular - 错误类型错误 : Cannot read property 'replace' of null

转载 作者:行者123 更新时间:2023-12-02 14:48:46 24 4
gpt4 key购买 nike

尽管我的应用程序运行正常,但我遇到了类型错误。

"ERROR TypeError: Cannot read property 'replace' of null"

如何解决这个问题? enter image description here

if (isInitial) {

// Add Data Rows (initially)
for(const row of rows) {

const clientVisitGuid = row[2];
const location = row[3];

row[5] = row[5].replace(/\//g, '\/\u200B');
const service = row[5];

const rowId = `${service || 'zzz'}_${location}_${clientVisitGuid}`;
const sortString = `${service || 'zzz'}_${location}_${clientVisitGuid}`;
const daysPastDischarge = parseInt(row[6]);
const isMarked = parseInt(row[7]) === 1 ? true : false;

if (cbt.hasBodyRow(rowId) === false) {

const values: Array<[string, string | number]> = [];
let isAllClear = true;
for(let i = 0; i < row.length; i++) {
const colId: string = cbt.headerRow.headerCols[i].id;
const colVal: string | number = row[i];
if (cbt.headerRow.headerCols[i].isFlag === true && colVal !== 1) {
isAllClear = false;
}
values.push([colId, colVal]);
}

const valueHash = hash(JSON.stringify(row));

cbt.addBodyRow(
rowId,
values,
valueHash,
sortString,
daysPastDischarge,
isMarked,
isAllClear,
true,
);
}
}

最佳答案

要修复错误,您需要在尝试替换字符串之前检查变量是否存在。用这样的 if 语句包装它:

if(row[5]) {
row[5] = row[5].replace(/\//g, '\/\u200B');
const service = row[5];
}

关于angular - 错误类型错误 : Cannot read property 'replace' of null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57172089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com