带复选框且支持搜索功能的下拉列表11

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;
                    //forceAll为true指的是单击下拉框
                    if (forceAll){
                    	//清除过滤条件
                        this.store.clearFilter();
                        for(var i = 0; i < this.store.getCount(); i++){
                        	//store里头存在等于全选的一项,把flag置为false,且跳出循环
                            if("全选" == this.store.getAt(i).get('name')){
	                            rec = this.store.getAt(i);
	                            this.store.remove(this.store.getAt(i));
                            }
                        }
                        //如果recor不为空,并且store里存在元素,并且isExitsAll为真
                        //就往store里插入一项为全选的record的记录
                        if(rec !== undefined && rec !== null 
                            && this.store.getCount() > 0){
                            this.store.insert(0,rec);
                        }
                    }
                    //为false指的是键盘输入
                    else{
                    	//combobox中输入的值是否和store中的相匹配
                    	var rec_flag = false;                    	
                	    if(this.store.getCount()==0){
                	    	rec_flag = true;
                	    }
                	    //循环判断store中是否存在等于全选的记录,如果存在就把这一项移除掉
                	    //并且把rec_flag置为true
                	    for(var i = 0; i < this.store.getCount(); i++){
                            if("全选" == this.store.getAt(i).get('name')){
                            	rec = this.store.getAt(i);
                            	//移除存在等于全选的记录
	                            this.store.remove(this.store.getAt(i));
	                            rec_flag = true;
                            }
                        }
                        //根据在combobox中输入的值在store进行筛选
                    	this.store.filter(this.displayField, q);                    	
                        if(rec !== undefined && rec !== null && rec_flag){
                        	//store中的记录大于0就往store里头插入全选这一项纪录
                        	if(this.store.getCount()>0){
                        	    this.store.insert(0,rec);
                        	}
                        }
                    }
                    this.onLoad();
                }
                else{
                    this.store.baseParams[this.queryParam] = q;
                    this.store.load({
                        params: this.getParams(q)
                    });
                    this.expand();
                }
            }
            else{
                this.selectedIndex = -1;
                this.onLoad();
            }
        }
    },

你可能感兴趣的:(下拉列表)