gpt4 book ai didi

javascript - 如何过滤 ReactJS 中的数据收集

转载 作者:搜寻专家 更新时间:2023-11-01 04:16:04 25 4
gpt4 key购买 nike

我是 ReactJS 的新手,我想弄清楚它是如何工作的。

我在 JsBin 中尝试了一下,我已经成功地创建了一些组件来从 api 获取数据......但是,当我尝试实现 代码来过滤该集合时,我感到有点困惑.

这是 JsBin link我正在尝试实现过滤器功能。

你能帮我理解为什么它不起作用吗?谢谢。

最佳答案

ContentList 组件中,它应该使用 this.props.filterText,它将获取输入值并与您的数据进行比较。当输入值改变时,React 会重新渲染包含 this.state.filterText 的组件。您可以使用 mapfilter过滤它的方法。这是一个例子:

var ContentList = React.createClass({

render: function() {
var commentNodes = this.props.data.map(function(content) {
if(content.description === this.props.filterText){ <-- this makes the filter work !
return <ItemRow title={content.owner.login} body={content.description} slug={content.owner.avatar_url}></ItemRow>}
})
return (
<div className='contentList'>
{commentNodes}
</div>
)
}
})

关于javascript - 如何过滤 ReactJS 中的数据收集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30682881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com