日期选择器onSelect未从gridmvc.js插件触发

datepicker onselect is not firing From gridmvc.js plugin

本文关键字:插件 js gridmvc 选择器 onSelect 未从 日期      更新时间:2023-09-26
dateContainer.datepicker({
    defaultDate: this.filterValue,
    changeMonth: true,
    changeYear: true,
    dateFormat: 'MM-dd-yyyy',
    onSelect: function (dateText, t) {
        var type = $context.container.find(".grid-filter-type").val();
        $context.cb(type, dateText);
    }
});

我正在使用 gridmvc.js 和 bootstrap-datepicker.js插件。无论如何,OnSelect 事件都不会触发。我不知道是什么原因?

我不知道

是因为什么,问题发生了。但是我已经找到了临时解决方案。对于解决方案,您必须在 bootstrap-datepicker.js 中更改一行代码。(在更改和使用插件之前检查许可证)

case 'span':
                        if (!target.is('.disabled')) {
                            this.viewDate.setUTCDate(1);
                            if (target.is('.month')) {
                                var day = 1;
                                var month = target.parent().find('span').index(target);
                                var year = this.viewDate.getUTCFullYear();
                                this.viewDate.setUTCMonth(month);
                                this._trigger('changeMonth', this.viewDate);
                                if (this.o.minViewMode === 1) {
                                    this._setDate(UTCDate(year, month, day,0,0,0,0));
                                }
                            } else {
                                var year = parseInt(target.text(), 10)||0;
                                var day = 1;
                                var month = 0;
                                this.viewDate.setUTCFullYear(year);
                                this._trigger('changeYear', this.viewDate);
                                if (this.o.minViewMode === 2) {
                                    this._setDate(UTCDate(year, month, day,0,0,0,0));
                                }
                            }
                            this.showMode(-1); this.fill();

这里出现问题是因为调用了这个.fill()。

如果您在插件中注释此行,日期选择器不会以任何方式隐藏月份和年份更改。或者您可以通过以下方式进行更改,

if (target.is('.month')) {
                                if (!this._o.changeMonth) {
                                    this.fill();
                                }
                            }
                            else {
                                if (!this._o.changeYear) {
                                    this.fill();
                                }
                            }

然后,这将根据您在创建日期选择器时提供的参数起作用。