我想显示在技能数组上过滤的项目,例如,如果我选择“HTML”,则显示项目数组技能中所有带有“HTML”的项目。如果我选择两个技能,则显示具有两个技能的项目。我的项目有这些数据:const data = [ { id: "1", name: "project1", techno: ["JAVASCRIPT", "REACTJS"], imageUrl: "link", }, { id: "2", name: "project2", techno: ["HTML", "CSS", "SASS"], imageUrl: "link", }, { id: "3", name: "project3", techno: ["JAVASCRIPT", "HTML"], imageUrl: "link", }];还有我的arrayFilterconst filter = ["JAVASCRIPT", "HTML", "CSS"];目前,我有这个代码: data .filter((filter) => filter.techno.includes(filter[0])) .map(({ id, ...otherProps }) => ( <ProjectItem key={id} {...otherProps} /> ))谢谢您的帮助
1 回答
郎朗坤
TA贡献1921条经验 获得超9个赞
你可以使用每一个
const data = [
{
id: '1',
name: 'project1',
techno: ['JAVASCRIPT', 'REACTJS'],
imageUrl: 'link',
},
{
id: '2',
name: 'project2',
techno: ['HTML', 'CSS', 'SASS'],
imageUrl: 'link',
},
{
id: '3',
name: 'project3',
techno: ['JAVASCRIPT', 'HTML', 'REACTJS'],
imageUrl: 'link',
},
];
const filter = ['JAVASCRIPT', 'REACTJS'];
const result = data.filter(d => filter.every(t => d.techno.includes(t)));
console.log(result);
添加回答
举报
0/150
提交
取消