react.js ant 设计范围过滤器,带有开始和结束日期错误 [英] react.js ant design range filter with start and end dates error

查看:26
本文介绍了react.js ant 设计范围过滤器,带有开始和结束日期错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 react.js

您可能会看到此处

的示例

目标是发送到后端以搜索包含 2 个日期的数组:开始日期和结束日期.我想它正在那里发送一个 moment.js 对象,它应该以某种方式转换为字符串,但我不知道在哪里做.欢迎任何解决方法的想法

解决方案

改变将值传递给 setSelectedKeys 函数的方式,setSelectedKeys 函数接受一个数组作为值.

所以为了让它起作用.把你的代码改成这个.

onChange={e =>setSelectedKeys([e.format("DD.MM.YYYY")])}

此外,您必须处理日期选择器的清除事件,以避免将空值传递给 setSelectedKeys 函数.

onChange={e =>setSelectedKeys(e !== null ? [e.format("DD.MM.YYYY")] : [])}

in my react.js ant.design project I am trying to implement table range filtering based on 2 date pickers: for start date and end date. I inserted them into filter drop down, but when I hit the search button, I get an error sayng that values.some is not a function.

Example you may see HERE

The goal is to send to backend for searching an array of 2 dates: start date and end date. I suppose it is sending a moment.js object there which is should be converted to string somehow, but I dont know where to do that. Any ideas how to fix it would be welcome

解决方案

Change the way on how you pass the values to setSelectedKeys function, the setSelectedKeys function accepts an array as the value.

So in order for this to work. Change your code into this.

onChange={e => setSelectedKeys([e.format("DD.MM.YYYY")])}

Also you must handle the on clear event of the datepicker to avoid passing null value to setSelectedKeys function.

onChange={e => setSelectedKeys(e !== null ? [e.format("DD.MM.YYYY")] : [])}

这篇关于react.js ant 设计范围过滤器,带有开始和结束日期错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆