我具有以下功能,可以过滤掉我的引导表中的“标题”。我也想按'id'过滤。
search(term: string) {
if (!term) {
this.filterData = this.data;
} else {
this.filterData = this.data.filter(x =>
x.title.trim().toLowerCase().includes(term.trim().toLowerCase())
);
}
}
如何也添加'id'参数?
正在过滤的json数组如下
[
{
"albumId": 1,
"id": 1,
"title": "accusamus beatae ad facilis cum similique qui sunt",
"url": "https://via.placeholder.com/600/92c952",
"thumbnailUrl": "https://via.placeholder.com/150/92c952"
},
{
"albumId": 1,
"id": 2,
"title": "reprehenderit est deserunt velit ipsam",
"url": "https://via.placeholder.com/600/771796",
"thumbnailUrl": "https://via.placeholder.com/150/771796"
}
]
答案 0 :(得分:2)
您应在过滤器中使用&&运算符,
this.filterData = this.data.filter(x =>
x.title.trim().toLowerCase().includes(term.trim().toLowerCase()) &&
x.id == yourId)
);