简体   繁体   English

如何修复 TypeError:无法读取未定义的属性?

[英]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.

相关问题 如何修复Uncaught TypeError:无法读取Dygraphs中未定义的属性'pageX'? - How to fix Uncaught TypeError: Cannot read property 'pageX' of undefined in Dygraphs? 如何解决“未捕获的TypeError:无法读取未定义的属性'number'”? - How to fix “Uncaught TypeError: Cannot read property 'number' of undefined”? 如何修复nodeJS中的“ TypeError:无法读取未定义的属性'then'” - How to fix “TypeError: Cannot read property 'then' of undefined” in nodeJS 如何修复JavaScript中的“ TypeError:无法读取未定义的属性'map'”? - How to fix “TypeError: Cannot read property 'map' of undefined” in JavaScript? 如何修复TypeError:无法读取未定义的属性“ push” - How to fix TypeError: Cannot read property 'push' of undefined 如何解决:“无法读取未定义TypeError的属性'init'”? - How do fix :“Cannot read property 'init' of undefined TypeError”? 如何修复“Uncaught TypeError: Cannot read property 'scrollHeight' of undefined”错误 - how to fix “Uncaught TypeError: Cannot read property 'scrollHeight' of undefined” error 如何解决这个问题 TypeError: Cannot read property 'roles' of undefined - how to fix this problem TypeError: Cannot read property 'roles' of undefined 如何修复 TypeError:无法读取未定义的属性“客户端” - How to fix the TypeError: Cannot read property 'Client' of undefined 如何修复未捕获的类型错误:无法读取未定义的属性“名称” - How to fix Uncaught TypeError: Cannot read property 'name' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM