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

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

问题描述

在我的react.js

示例您可能会看到这里

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

解决方案

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

因此,为了使其正常工作.将您的代码更改为此.

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

此外,您还必须处理datepicker的on clear事件,以避免将null值传递给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天全站免登陆