⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combo.js

📁 ext js demo ext学习资料
💻 JS
📖 第 1 页 / 共 2 页
字号:
            this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));        }    },    /**     * Allow or prevent the user from directly editing the field text.  If false is passed in,     * the user will only be able to select from the items defined in the dropdown list.  This method     * is the runtime equivalent of setting the editable config option at config time.     */    setEditable : function(value){        if(value == this.editable){            return;        }        this.editable = value;        if(!value){            this.el.dom.setAttribute('readOnly', true);            this.el.on('mousedown', this.onTriggerClick,  this);            this.el.addClass('x-combo-noedit');        }else{            this.el.dom.setAttribute('readOnly', false);            this.el.un('mousedown', this.onTriggerClick,  this);            this.el.removeClass('x-combo-noedit');        }    },    // private    onBeforeLoad : function(){        if(!this.hasFocus){            return;        }        this.innerList.update(this.loadingText ?               '<div class="loading-indicator">'+this.loadingText+'</div>' : '');        this.restrictHeight();        this.selectedIndex = -1;    },    // private    onLoad : function(){        if(!this.hasFocus){            return;        }        if(this.store.getCount() > 0){            this.expand();            this.restrictHeight();            if(this.lastQuery == this.allQuery){                if(this.editable){                    this.el.dom.select();                }                if(!this.selectByValue(this.value, true)){                    this.select(0, true);                }            }else{                this.selectNext();                if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){                    this.taTask.delay(this.typeAheadDelay);                }            }        }else{            this.onEmptyResults();        }        //this.el.focus();    },    // private    onTypeAhead : function(){        if(this.store.getCount() > 0){            var r = this.store.getAt(0);            var newValue = r.data[this.displayField];            var len = newValue.length;            var selStart = this.getRawValue().length;            if(selStart != len){                this.setRawValue(newValue);                this.selectText(selStart, newValue.length);            }        }    },    // private    onSelect : function(record, index){        if(this.fireEvent('beforeselect', this, record, index) !== false){            this.setValue(record.data[this.valueField || this.displayField]);            this.collapse();            this.fireEvent('select', this, record, index);        }    },    /**     * Returns the currently selected field value or empty string if no value is set.     * @return {String} value The selected value     */    getValue : function(){        if(this.valueField){            return typeof this.value != 'undefined' ? this.value : '';        }else{            return Ext.form.ComboBox.superclass.getValue.call(this);        }    },    /**     * Clears any text/value currently set in the field     */    clearValue : function(){        if(this.hiddenField){            this.hiddenField.value = '';        }        this.setRawValue('');        this.lastSelectionText = '';        this.applyEmptyText();    },    /**     * Sets the specified value into the field.  If the value finds a match, the corresponding record text     * will be displayed in the field.  If the value does not match the data value of an existing item,     * and the valueNotFoundText config option is defined, it will be displayed as the default field text.     * Otherwise the field will be blank (although the value will still be set).     * @param {String} value The value to match     */    setValue : function(v){        var text = v;        if(this.valueField){            var r = this.findRecord(this.valueField, v);            if(r){                text = r.data[this.displayField];            }else if(this.valueNotFoundText !== undefined){                text = this.valueNotFoundText;            }        }        this.lastSelectionText = text;        if(this.hiddenField){            this.hiddenField.value = v;        }        Ext.form.ComboBox.superclass.setValue.call(this, text);        this.value = v;    },    // private    findRecord : function(prop, value){        var record;        if(this.store.getCount() > 0){            this.store.each(function(r){                if(r.data[prop] == value){                    record = r;                    return false;                }            });        }        return record;    },    // private    onViewMove : function(e, t){        this.inKeyMode = false;    },    // private    onViewOver : function(e, t){        if(this.inKeyMode){ // prevent key nav and mouse over conflicts            return;        }        var item = this.view.findItemFromChild(t);        if(item){            var index = this.view.indexOf(item);            this.select(index, false);        }    },    // private    onViewClick : function(doFocus){        var index = this.view.getSelectedIndexes()[0];        var r = this.store.getAt(index);        if(r){            this.onSelect(r, index);        }        if(doFocus !== false){            this.el.focus();        }    },    // private    restrictHeight : function(){        this.innerList.dom.style.height = '';        var inner = this.innerList.dom;        var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);        this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);        this.list.beginUpdate();        this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);        this.list.alignTo(this.el, this.listAlign);        this.list.endUpdate();    },    // private    onEmptyResults : function(){        this.collapse();    },    /**     * Returns true if the dropdown list is expanded, else false.     */    isExpanded : function(){        return this.list.isVisible();    },    /**     * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.     * The store must be loaded and the list expanded for this function to work, otherwise use setValue.     * @param {String} value The data value of the item to select     * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the     * selected item if it is not currently in view (defaults to true)     * @return {Boolean} True if the value matched an item in the list, else false     */    selectByValue : function(v, scrollIntoView){        if(v !== undefined && v !== null){            var r = this.findRecord(this.valueField || this.displayField, v);            if(r){                this.select(this.store.indexOf(r), scrollIntoView);                return true;            }        }        return false;    },    /**     * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.     * The store must be loaded and the list expanded for this function to work, otherwise use setValue.     * @param {Number} index The zero-based index of the list item to select     * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the     * selected item if it is not currently in view (defaults to true)     */    select : function(index, scrollIntoView){        this.selectedIndex = index;        this.view.select(index);        if(scrollIntoView !== false){            var el = this.view.getNode(index);            if(el){                this.innerList.scrollChildIntoView(el, false);            }        }    },    // private    selectNext : function(){        var ct = this.store.getCount();        if(ct > 0){            if(this.selectedIndex == -1){                this.select(0);            }else if(this.selectedIndex < ct-1){                this.select(this.selectedIndex+1);            }        }    },    // private    selectPrev : function(){        var ct = this.store.getCount();        if(ct > 0){            if(this.selectedIndex == -1){                this.select(0);            }else if(this.selectedIndex != 0){                this.select(this.selectedIndex-1);            }        }    },    // private    onKeyUp : function(e){        if(this.editable !== false && !e.isSpecialKey()){            this.lastKey = e.getKey();            this.dqTask.delay(this.queryDelay);        }    },    // private    validateBlur : function(){        return !this.list || !this.list.isVisible();       },    // private    initQuery : function(){        this.doQuery(this.getRawValue());    },    // private    doForce : function(){        if(this.el.dom.value.length > 0){            this.el.dom.value =                this.lastSelectionText === undefined ? '' : this.lastSelectionText;            this.applyEmptyText();        }    },    /**     * Execute a query to filter the dropdown list.  Fires the beforequery event prior to performing the     * query allowing the query action to be canceled if needed.     * @param {String} query The SQL query to execute     * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters     * in the field than the minimum specified by the minChars config option.  It also clears any filter previously     * saved in the current store (defaults to false)     */    doQuery : function(q, forceAll){        if(q === undefined || q === null){            q = '';        }        var qe = {            query: q,            forceAll: forceAll,            combo: this,            cancel:false        };        if(this.fireEvent('beforequery', qe)===false || qe.cancel){            return false;        }        q = qe.query;        forceAll = qe.forceAll;        if(forceAll === true || (q.length >= this.minChars)){            if(this.lastQuery != q){                this.lastQuery = q;                if(this.mode == 'local'){                    this.selectedIndex = -1;                    if(forceAll){                        this.store.clearFilter();                    }else{                        this.store.filter(this.displayField, q);                    }                    this.onLoad();                }else{                    this.store.baseParams[this.queryParam] = q;                    this.store.load({                        params: this.getParams(q)                    });                    this.expand();                }            }else{                this.selectedIndex = -1;                this.onLoad();               }        }    },    // private    getParams : function(q){        var p = {};        //p[this.queryParam] = q;        if(this.pageSize){            p.start = 0;            p.limit = this.pageSize;        }        return p;    },    /**     * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.     */    collapse : function(){        if(!this.isExpanded()){            return;        }        this.list.hide();        Ext.get(document).un('mousedown', this.collapseIf, this);        Ext.get(document).un('mousewheel', this.collapseIf, this);        this.fireEvent('collapse', this);    },    // private    collapseIf : function(e){        if(!e.within(this.wrap) && !e.within(this.list)){            this.collapse();        }    },    /**     * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.     */    expand : function(){        if(this.isExpanded() || !this.hasFocus){            return;        }        this.list.alignTo(this.el, this.listAlign);        this.list.show();        Ext.get(document).on('mousedown', this.collapseIf, this);        Ext.get(document).on('mousewheel', this.collapseIf, this);        this.fireEvent('expand', this);    },    // private    // Implements the default empty TriggerField.onTriggerClick function    onTriggerClick : function(){        if(this.disabled){            return;        }        if(this.isExpanded()){            this.collapse();            this.el.focus();        }else {            this.hasFocus = true;            if(this.triggerAction == 'all') {                this.doQuery(this.allQuery, true);            } else {                this.doQuery(this.getRawValue());            }            this.el.focus();        }    }    /** @cfg {Boolean} grow @hide */    /** @cfg {Number} growMin @hide */    /** @cfg {Number} growMax @hide */    /**     * @hide     * @method autoSize     */});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -