按名称和日期搜索react redux tyspript中的过滤器
我目前正在学习React,更具体地说是Typescript和Redux。我需要用名称和日期进行搜索过滤器。我用Antd(带钩子)的Rangepicker制作了一个日期过滤器,但我不知道如何用名字制作一个。
const [searchTerm, setSearchTerm] = useState<string[]>([]);
<Space direction="vertical" size={12}>
<RangePicker onChange={(dates, datesString) => {setSearchTerm(datesString)}}/>
</Space>
<Table
className='tablica'
columns={columns}
dataSource={todoHistory.filter((val) => {
if(searchTerm.length > 0){
if(moment(val.datum).diff(searchTerm[0]) >= 0 &&
moment(val.datum).diff(searchTerm[1]) <= 0 ) {
return val
}
}else{ return val; }
)}
/>
I'm currently learning about react, more specifically about typescript and redux. I need to make a search filter with name and date. I made a date filter with RangePicker by antd(with hooks), but I don't know how to make one with a name.
const [searchTerm, setSearchTerm] = useState<string[]>([]);
<Space direction="vertical" size={12}>
<RangePicker onChange={(dates, datesString) => {setSearchTerm(datesString)}}/>
</Space>
<Table
className='tablica'
columns={columns}
dataSource={todoHistory.filter((val) => {
if(searchTerm.length > 0){
if(moment(val.datum).diff(searchTerm[0]) >= 0 &&
moment(val.datum).diff(searchTerm[1]) <= 0 ) {
return val
}
}else{ return val; }
)}
/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现所需的一种方法是创建另一个
状态
以保持名称
,该名称将用于过滤,并在todohistory.filter.filter 。
请注意,我已将第一个过滤器的实现更改为返回
boolean
,因为它更准确地使用了filter
期望返回的内容。One way to achieve what you need is by creating another
state
to hold thename
that will be used to filter, and use it in thetodoHistory.filter
.Note that I've changed the implementation of the first filter to return a
boolean
, as it is more accurate with what thefilter
is expecting to be returned. filter docs我设法通过使用效果挂钩解决了这个问题,并创建了另一个状态。
因此,我创建了另一个状态:
然后使用效果挂钩:
},[searchText]);
然后我做了一个输入:
I managed to solve this problem through useEffect hook and creating another state.
So I created another state:
And then useEffect hook:
},[searchText]);
And then I made an Input: