[英]How to fix TypeError: Cannot read property of undefined?
My UI crashes and I am getting the following error:我的用户界面崩溃了,我收到以下错误:
TypeError: Cannot read property 'filter' of undefined
at v (helper.js:16)
at i (lodash.min.js:9)
at t (lodash.min.js:59)
at value (CheckAll.js:15)
Here's a snippet of the helper.js code:下面是 helper.js 代码的一个片段:
export const updatedChecked = (items, checked) => items.map(item => ({ ...item, checked }));
export const filterChecked = (items, checked) => items.filter(item => item.checked === checked);
export const moveAtTheTop = (items, itemIds) => pureReverse(itemIds).reduce((acc, v) => {
const toCutIndex = acc.findIndex(item => item.id === v);
const toCut = acc.splice(toCutIndex, 1)[0];
toCut.checked = true;
acc.unshift(toCut);
return acc;
}, updateChecked(items, false));
export const normalizeSrcItems = items => filterChecked(items, true).map(item => item.id);
It's probably because you send undefined
in items
argument when you call normalizeSrcItems
.这可能是因为您在调用normalizeSrcItems
时在items
参数中发送了undefined
。 You need to check it where you call it你需要在你调用它的地方检查它
if (items) {
normalizeSrcItems(items)
}
, or check why you have empty items, perhaps you get it in wrong way ,或者检查为什么你有空物品,也许你以错误的方式得到它
Obviously, calling显然,调用
items.filter(...)
Looks like items is undefined.看起来项目未定义。 Quick fix is:快速修复是:
(items || []).filter(...)
But it might not solve the problem, why items are undefined.但它可能无法解决问题,为什么项目未定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.