zoukankan      html  css  js  c++  java
  • Ext4.X--年月选择组件

    1.类的定义:

      在Ext项目开发中,有时会用到只选择年月的日期组件,下面的代码会帮你完成,只需向下面的类拷贝到你的项目中即可使用。

    Ext.define('Ext.form.field.Month', {
        extend:'Ext.form.field.Date',
        alias: 'widget.monthfield',
        requires: ['Ext.picker.Month'],
        alternateClassName: ['Ext.form.MonthField', 'Ext.form.Month'],
        selectMonth: null,
        createPicker: function() {
            var me = this,
                format = Ext.String.format;
            return Ext.create('Ext.picker.Month', {
                pickerField: me,
                ownerCt: me.ownerCt,
                renderTo: document.body,
                floating: true,
                hidden: true,
                focusOnShow: true,
                minDate: me.minValue,
                maxDate: me.maxValue,
                disabledDatesRE: me.disabledDatesRE,
                disabledDatesText: me.disabledDatesText,
                disabledDays: me.disabledDays,
                disabledDaysText: me.disabledDaysText,
                format: me.format,
                showToday: me.showToday,
                startDay: me.startDay,
                minText: format(me.minText, me.formatDate(me.minValue)),
                maxText: format(me.maxText, me.formatDate(me.maxValue)),
                listeners: { 
            select:        { scope: me,   fn: me.onSelect     }, 
            monthdblclick: { scope: me,   fn: me.onOKClick     },    
            yeardblclick:  { scope: me,   fn: me.onOKClick     },
            OkClick:       { scope: me,   fn: me.onOKClick     },    
            CancelClick:   { scope: me,   fn: me.onCancelClick }        
                },
                keyNavConfig: {
                    esc: function() {
                        me.collapse();
                    }
                }
            });
        },
        onCancelClick: function() {
            var me = this;    
        me.selectMonth = null;
            me.collapse();
        },
        onOKClick: function() {
            var me = this;    
        if( me.selectMonth ) {
                   me.setValue(me.selectMonth);
                me.fireEvent('select', me, me.selectMonth);
        }
            me.collapse();
        },
        onSelect: function(m, d) {
            var me = this;    
        me.selectMonth = new Date(( d[0]+1 ) +'/1/'+d[1]);
        }
    }); 

    2.用法:

    '请输入年月',
    {
        xtype:'monthfield',
        format:"Y-m",
        id:'monthId',
        value:new Date()
    }
                                        

    3.运行效果:

  • 相关阅读:
    WINDOWS API ——GETFILETIME——获取文件时间
    lua 源码分析之线程对象lua_State
    GPL、BSD、MIT、Mozilla、Apache、LGPL开源协议介绍
    BOOST 线程完全攻略
    宏定义中#和##符号的使用和宏定义展开问题
    weak_ptr<T>智能指针
    轻松记住大端小端的含义(附对大端和小端的解释)
    关于VC预定义常量_WIN32,WIN32,_WIN64
    VC 预定义宏
    php技术之路
  • 原文地址:https://www.cnblogs.com/zhougaojun/p/3798809.html
Copyright © 2011-2022 走看看