首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在ngx-daterangepicker-material中选择相同值的日期范围内的不同日期?

如何在ngx-daterangepicker-material中选择相同值的日期范围内的不同日期?
EN

Stack Overflow用户
提问于 2021-07-27 06:00:42
回答 1查看 50关注 0票数 0

我有两个预定义的日期范围,如“当前月份”和“当前季度”。目前,这两个范围代表相同的日期值(因为刚刚开始的季度和月份)。当我想选择“当前季度”时,它会自动选择“当前月份”。无法选择“当前季度”,该按钮未处于活动状态。这看起来不像是一个用户友好的行为。是否有任何配置允许用户选择具有相同值的不同日期范围?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-29 21:29:37

不幸的是,ngx-daterangepicker-material的设计不允许多个日期完全相同的范围。我能够重现你在这里看到的症状:Stackblitz

看一下您正在使用的包的代码,您将在calculateChosenLabel()方法中看到:

代码语言:javascript
复制
    calculateChosenLabel () {
            if (!this.locale || !this.locale.separator) {
                this._buildLocale();
            }
            let customRange = true;
            let i = 0;
            if (this.rangesArray.length > 0) {
                for (const range in this.ranges) {
                    if (this.ranges[range]) {
                        if (this.timePicker) {
                            const format = this.timePickerSeconds ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm';
                            // ignore times when comparing dates if time picker seconds is not enabled
                          if (this.startDate.format(format) === this.ranges[range][0].format(format)
                            && this.endDate.format(format) === this.ranges[range][1].format(format)) {
                                customRange = false;
                                this.chosenRange = this.rangesArray[i];
                                break;
                            }
                        } else {
                            // ignore times when comparing dates if time picker is not enabled
                            if (this.startDate.format('YYYY-MM-DD') === this.ranges[range][0].format('YYYY-MM-DD')
                              && this.endDate.format('YYYY-MM-DD') === this.ranges[range][1].format('YYYY-MM-DD')) {
                                customRange = false;
                                this.chosenRange = this.rangesArray[i];
                                break;
                            }
                        }
                        i++;
                    }
                }

它循环遍历您指定的范围,并匹配根据该范围选择的开始和结束日期。

2.除非您显示时间选择器,否则它会忽略时间值,因此即使尝试使用时间偏移量来修改它也不会起作用

目前没有任何标志或选项可以覆盖此设置。

看起来您最好的选择是使用Open a new issue来请求使用唯一的范围标识符,而不仅仅是比较日期

或者导入项目的源代码,并根据自己的需要进行修改

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68536772

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档