javascript - 如何解决 TypeError: Cannot read property 'filter' of undefined error after replace lodash find function with native JS filter function?
问题描述
我正在尝试删除 lodash find 功能,所以我的更改基本上是替换这一行:
const current = find(items, elem => elem.id === item.id);
有了这个:
const current = items ? items.filter(function(x) {
return x.id === item.id;
}) : null;
但我收到了这个错误:
app.js:659 Uncaught (in promise) TypeError: Cannot read property 'filter' of undefined
解决方案
我不知道为什么过滤器不起作用,但这条线解决了问题
const current = items.find(x => x.id === item.id);
推荐阅读
- javascript - SSL 错误 - 版本号错误(HTTPS 到 HTTP)
- intellij-idea - IntelliJ 中的版权管理令人困惑
- android - 如何在 android 中使用边界回调分页库在 nasa apod api 中显示新数据?
- cors - 预检响应 403 被禁止。如何在没有 x-api-key 的情况下允许选项方法?
- c++ - 1.70.0版本后如何继承boost :: asio :: streambuf?
- awk - 如何打印多个文件的最后一行?
- oracle - 如何将值从一个表传递到另一个表的对象列?
- angular - 角材料可扩展表不起作用
- python - 主题建模和潜在狄利克雷分配 (LDA)
- python - GMS 3.4.x 中的 Python - 使用 matplotlib.pyplot 时 DM 崩溃:无法找到或加载 Windows 的 Qt 平台插件