【问题标题】:Datepicker onClose event not firing when used as a backgrid editor用作背景编辑器时,日期选择器 onClose 事件未触发
【发布时间】:2015-05-07 09:58:10
【问题描述】:

我已经搜索了网络,但我找不到任何解决这个问题的方法。这是我的sn-p。

Backgrid.CustomDateCell = Backgrid.DateCell.extend({
    editor: Backgrid.InputCellEditor.extend({
        attributes: {
            type: "text"
          },
        events: {},
        initialize: function(){
            Backgrid.InputCellEditor.prototype.initialize.apply(this, arguments);
            var _input = this;
            $(this.el).prop('readonly', true);
            $(this.el).datepicker({
                autoclose: true,
                todayHighlight: true,
                format: "mm/dd/yyyy",
                viewMode: "months",
                minViewMode: "months",
                onClose: function(dateText, inst){
                    var command = new Backgrid.Command({});
                    _input.model.set(_input.column.get("name"), dateText);
                    _input.model.trigger("backgrid:edited", _input.model, _input.column, command);
                    command = _input = null;
                }
            });
        }
    })
});

所以基本上,我想要的是触发 backgrid:edited 的 backgrid 单元模型。但似乎我在这里遗漏了一些东西。永远不会调用 onClose 事件,并且控制台中不会显示任何错误。我也尝试了 onSelect 事件,但结果相同。

提前致谢

【问题讨论】:

  • 这是什么日期选择器? viewModeautoclose 看起来像引导选项,但 onClose 是一个 jqueryui 选项
  • 它是一个引导日期选择器。我忽略了这一点。感谢您的提醒。

标签: javascript jquery backbone.js underscore.js backgrid


【解决方案1】:

如 cmets 中所述:

这是一个引导日期选择器,因此onClose 不是有效选项。而是将侦听器附加到 hide 事件:

        $(this.el).datepicker({
            autoclose: true,
            todayHighlight: true,
            format: "mm/dd/yyyy",
            viewMode: "months",
            minViewMode: "months"
        });
        $(this.el).on("hide", function(e) {
                var command = new Backgrid.Command({});
                _input.model.set(_input.column.get("name"), e.date);
                _input.model.trigger("backgrid:edited", _input.model, _input.column, command);
                command = _input = null;
            });

e.date 应该给你相当于dateText

【讨论】:

  • 非常感谢您的帮助。现在触发了。所选日期仍然存在问题,因为它始终显示 1970 年 1 月。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-04
  • 2020-02-20
  • 2016-08-28
相关资源
最近更新 更多