You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在React过滤器中加入API返回的更多字段(如email)

多字段筛选实现代码修改

直接在过滤条件中用逻辑或(||)同时判断name和email字段即可,注意统一转为小写避免大小写敏感问题:

useEffect(() => {
  const results = filtered.filter(
    (res) =>
      res.name.toLowerCase().includes(result.toLowerCase()) ||
      res.email.toLowerCase().includes(result.toLowerCase())
  )
  setData(results);
}, [result]);
//console.log(data)

如果后续需要加入更多筛选字段,继续用||追加判断条件即可,比如res.phone.toLowerCase().includes(result.toLowerCase())。

内容的提问来源于stack exchange,提问作者Bigboss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 13:15:28