如何在反应中使用过滤器?

知乎

我正在使用以太坊和 React 构建签到应用程序。

checkinplaceidand username,我想按 id 过滤数组。

现在,我的代码是这样的

{ this.props.checkins.map((checkin, key) => {
  return(
    <div key={key}>
      <p>ID{checkin.placeid}, Address:{checkin.username}</p>
    </div>
  )
})}

请你给我任何建议。

六月 L。

使用.filter()您可以根据条件过滤数组,该函数返回满足条件的项目数组。

所述过滤器()方法创建填充有通过测试(作为函数提供的)所有的数组元素的数组。

const filtered = this.props.checkins.filter(item => item.placeid === someid);

{ filtered.map((checkin, key) => {
  return(
    <div key={key}>
      <p>ID{checkin.placeid}, Address:{checkin.username}</p>
    </div>
  )
 });
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章