angular6 - 类型“{}”上不存在属性“过滤器”
问题描述
查询后我有一个这样的对象。我需要根据年份过滤它。
这是我的对象。
(6) [{…}, {…}, {…}, {…}, {…}, {…}]
0: {title: "PERSONAL", subtitle: "The standard version", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit", year: "2018", …}
1: {title: "STUDENT", subtitle: "Most popular choice", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit", year: "2017", …}
2: {title: "BUSINESS", subtitle: "For the whole team", description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit", year: "2018", …}
我使用以下代码进行过滤。
users = {};
ngOnInit() {
this.users.filter((user) => user.year == '2018');
}
但我得到了error TS2339: Property 'filter' does not exist on type '{}'.
谁能帮我解决这个问题?
解决方案
如果您已经将上述对象分配给用户。
users: any;
users =[{…}, {…}, {…}, {…}, {…}, {…}];
然后删除此行
// users = {}; remove this line it will work
ngOnInit() {
this.users.filter((user) => user.year == '2018');
}
当它已经是一个数组变量时你的分配对象
推荐阅读
- sparql - SPARQL 语法更正
- sharepoint - MS Flow SharePoint“授予访问权限”操作因“项目不存在”而失败
- laravel - 向 Laravel 中的所有用户发送每周电子邮件的方法
- java - 如何使用 LatLng 获取起始位置/位置。我确实有一个移动的当前位置/位置
- java - 如何从文本文件中读取单个字符并将它们存储到二维数组中?
- python - 如何显示DataFrame的前N行
- react-native - 未捕获的错误:EXGL:gl.texImage2D() 的像素数据参数无效
- rust - Hello World Rust 程序编译,但执行导致无授权错误
- html - CSS - 在固定的响应式导航菜单中对齐项目
- java - gradle 多模块 kotlin jacoco 覆盖率报告损坏