ExtJS基礎知識總結(二)

來源:互聯網
上載者:User

標籤:網上   sse   選擇   form   mon   com   blog   setvalue   概述   

概述

  1、ExtJS 5不支援日期選擇框中只選擇年月,為了滿足ExtJs5可以實現選擇年月的功能,查詢網上資料,整理出來了相應的處理方式,最終實現的效果如:

     

 

  2、ExtJS 控制項豐富,如果需要實現下拉式清單控制項ComboBox中含有Check樣式的皮膚,只需要在ComboBox控制項中監聽相應的下拉事件和選擇事件即可。實現的效果如下:

  

 

日曆控顯示年月的實現方式

1、編寫ext-extendmonth.js,代碼內容如下

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,            pickerConfig;        pickerConfig = {            pickerField: me,            ownerCmp: me,            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();                }            }        };        if (Ext.isChrome) {            me.originalCollapse = me.collapse;            pickerConfig.listeners.boxready = {                fn: function () {                    this.picker.el.on({                        mousedown: function () {                            this.collapse = Ext.emptyFn;                        },                        mouseup: function () {                            this.collapse = this.originalCollapse;                        },                        scope: this                    });                },                scope: me,                single: true            }        }        return Ext.create(‘Ext.picker.Month‘, pickerConfig);    },    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、引入ext-extendmonth.js以及修改預顯示控制項  xtype: ‘monthfield‘   屬性值

    //頭部功能表列    var proctoolbarText = Ext.create(‘Ext.toolbar.Toolbar‘, {        renderTo: ‘ReportData‘,        items: [{            xtype: ‘monthfield‘,            id: ‘CountData‘,            width: 180,            labelWidth: 30,            format: ‘Y-m‘,            fieldLabel: ‘日期‘,            emptyText: ‘請輸入開始時間‘,            editable: false,        //不可編輯            value: Ext.get("countDate").getValue()        }]});

下拉式清單控制項ComboBox中含有Check實現

1、自訂JS控制項Checktool

var Checktool=Ext.create(‘Ext.form.field.ComboBox‘,{        name : ‘cmb‘,        fieldLabel : ‘人員‘,        margin:‘2 0 2 0‘,        labelWidth : 135,        labelAlign : ‘right‘,        editable : false,        allowBlank : false,        multiSelect : true,        store : {            fields : [‘personId‘, ‘personName‘],            data : [                {‘personId‘:‘0‘,personName:‘張三‘},                {‘personId‘:‘1‘,personName:‘李四‘},                {‘personId‘:‘2‘,personName:‘王五‘},                {‘personId‘:‘3‘,personName:‘小名‘}            ]        },        listConfig : {            itemTpl : Ext.create(‘Ext.XTemplate‘,‘<input type=checkbox>{[values.personName]}‘),            onItemSelect : function(record) {                var node = this.getNode(record);                if (node) {                    Ext.fly(node).addCls(this.selectedItemCls);                    var checkboxs = node.getElementsByTagName("input");                    if (checkboxs != null)                        var checkbox = checkboxs[0];                    checkbox.checked = true;                }            },            listeners : {                itemclick : function(view, record, item, index, e, eOpts) {                    var isSelected = view.isSelected(item);                    var checkboxs = item.getElementsByTagName("input");                    if (checkboxs != null) {                        var checkbox = checkboxs[0];                        if (!isSelected) {                            checkbox.checked = true;                        } else {                            checkbox.checked = false;                        }                    }                }            }        },        queryMode : ‘local‘,        displayField : ‘personName‘,        valueField : ‘personId‘,          });

 2、ExtJS引用控制項即可

//頭部功能表列    var proctoolbarText = Ext.create(‘Ext.toolbar.Toolbar‘, {        renderTo: ‘ReportData‘,        items: [        Checktool        ]});        

 

ExtJS基礎知識總結(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.