作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尽管我的应用程序运行正常,但我遇到了类型错误。
"ERROR TypeError: Cannot read property 'replace' of null"
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/
我是一名优秀的程序员,十分优秀!