javascript - ExtJS xtype 时间字段 - 设置默认选择

标签 javascript extjs time-select

我继承了一个使用 ExtJS 的应用程序,但对其约定相对不熟悉。

我有一个用于时间输入的选择框,默认为传入的时间。是否可以将 selected = selected 设置为其默认值?目前显示默认时间,但当您单击该框时,选项列表默认为第一个值(因此,如果默认时间为下午 2 点,当您单击选择替代时间时,您将被带到中午 12 点而不是下午 2 点)。

代码:

{
            xtype: 'timefield',
            id: 'timeselect',
            name: 'starttime',
            fieldLabel: 'Start Time',
            labelWidth: 80,
            labelAlign: 'right',
            width: 160,
            minValue: '12:00 AM',
            maxValue: '11:55 PM',
            value: MyApp.config.AppConfig.time, //Current time rounded to hour
            increment: 15
        },

谢谢!

编辑:澄清。选择框显示页面加载的正确时间。但是,当用户单击选择时,他们将被带到选项列表的开头(在本例中为 12:00 am)。我希望选项列表默认为所选时间(类似于)。谢谢!

编辑#2:应用程序使用 v4.0.7

最佳答案

解决方案很简单:升级您的 Ext 版本!没那么简单吗?同时修补它。我必须承认,我试图将 Ext.form.field.Time v4.2 的代码复制到 the fiddle 中。 。那行不通。这是一种更简洁的方法:

Ext.define('Ext.ux.fix.Ext.form.field.Time.CurrentSelectionOnExpand', {
    override: 'Ext.form.field.Time'

    ,initComponent: function() {
        this.callParent();
        this.on({
            scope: this
            ,delay: 1 // let render
            ,expand: function() {
                this.highlightCurrent();
            } 
        });
    }

    // copied from Ext.view.BoundListKeyNav.method#highlightAt()
    ,highlightCurrent: function() {
        var me = this,
            picker = me.picker,
            index = picker.store.find('disp', me.getRawValue()),
            item = picker.all.item(index)
        if (item) {
            item = item.dom;
            picker.highlightItem(item);
            picker.getTargetEl().scrollChildIntoView(item, false);
        }
    }
});

关于javascript - ExtJS xtype 时间字段 - 设置默认选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20665857/

相关文章:

javascript - 如何使用获取请求的结果更新文本框

javascript - ExtJS 5.0 : Grid remoteSort always sorts by the default 'sorters' only

extjs - 如何将工具栏中的元素左、中、右对齐

jquery - 如何让 Bootstrap(插件)的 ClockPicker 出现在 Bootstrap Modal 弹出表单中?

javascript - 按下回车键时不刷新页面

javascript - ISP注入(inject)广告导致js无法正常运行

javascript - php根据html切换开关显示数据库中的数据

extjs - 在视口(viewport)中放置一个模态窗口

ruby-on-rails - ruby rails : time_select default value