EXT2.0 多选下拉框

预览:
1211600597-clip-1kb.png

调用方法:

None.gif < INPUT  TYPE =""  NAME =""  id ='multiselect' >
ExpandedBlockStart.gifContractedBlock.gif
< script > dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gifExt.onReady(
function() dot.gif{
InBlock.gif
InBlock.gif    
var arr = [['1''项一'], ['2''项二'], ['3''项三'],['4''项四'],['5''项五']];
InBlock.gif    
var arr2 = [['1''项一'], ['2''项二']];
InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
var auto_field = new Ext.form.MultiSelectField(dot.gif{
InBlock.gif        applyTo:
'multiselect',  
InBlock.gif        hiddenName:
'hid',  //Ext.get('hid').getValue() 可以得到索引号ID数组
InBlock.gif        contextArray : arr,
InBlock.gif        fieldLabel : 
'adfadsf',
InBlock.gif        id : 
'test',
InBlock.gif        defaltValueArray:arr2,
InBlock.gif        name : 
'test'
ExpandedSubBlockEnd.gif    }
);
InBlock.gif
ExpandedBlockEnd.gif}
);
None.gif
</ script >

EXT扩展组件:

ExpandedBlockStart.gif ContractedBlock.gif Ext.form.MultiSelectField  =  Ext.extend(Ext.form.TriggerField,  dot.gif {
InBlock.gif    readOnly : 
true,
ExpandedSubBlockStart.gifContractedSubBlock.gif    defaultAutoCreate : 
dot.gif{
InBlock.gif        tag : 
"input",
InBlock.gif        type : 
"text",
InBlock.gif        size : 
"24",
InBlock.gif        autocomplete : 
"off"
ExpandedSubBlockEnd.gif    }
,
InBlock.gif    displayField : 
'text',
InBlock.gif    contextArray : undefined, 
InBlock.gif    valueField : undefined,
InBlock.gif    hiddenName : undefined,
InBlock.gif    listWidth : undefined,
InBlock.gif    minListWidth : 
50,
InBlock.gif    defaltValueArray:undefined,
InBlock.gif    layerHeight : undefined,
InBlock.gif    minLayerHeight : 
60,
InBlock.gif    value : undefined,
ExpandedSubBlockStart.gifContractedSubBlock.gif    baseParams : 
dot.gif{},
InBlock.gif    checkpanel : undefined,
ExpandedSubBlockStart.gifContractedSubBlock.gif    initComponent : 
function() dot.gif{
InBlock.gif        Ext.form.MultiSelectField.superclass.initComponent.call(
this);
InBlock.gif        
this.addEvents('select''expand''collapse''beforeselect');
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (this.transform) dot.gif{
InBlock.gif            
this.allowDomMove = false;
InBlock.gif            
var s = Ext.getDom(this.transform);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (!this.hiddenName) dot.gif{
InBlock.gif                
this.hiddenName = s.name;
ExpandedSubBlockEnd.gif            }

InBlock.gif            s.name 
= Ext.id();
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (!this.lazyRender) dot.gif{
InBlock.gif                
this.target = true;
InBlock.gif                
this.el = Ext.DomHelper.insertBefore(s, this.autoCreate
InBlock.gif                        
|| this.defaultAutoCreate);
InBlock.gif                Ext.removeNode(s);
InBlock.gif                
this.render(this.el.parentNode);
InBlock.gif                
ExpandedSubBlockStart.gifContractedSubBlock.gif            }
 else dot.gif{
InBlock.gif                Ext.removeNode(s);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    onRender : 
function(ct, position) dot.gif{
InBlock.gif        Ext.form.MultiSelectField.superclass.onRender.call(
this, ct, position);
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (this.hiddenName) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
this.hiddenField = this.el.insertSibling(dot.gif{
InBlock.gif                tag : 
'input',
InBlock.gif                type : 
'hidden',
InBlock.gif                name : 
this.hiddenName,
InBlock.gif                id : (
this.hiddenId || this.hiddenName)
ExpandedSubBlockEnd.gif            }
'before'true);
InBlock.gif            
this.hiddenField.value = this.hiddenValue !== undefined
InBlock.gif                    
? this.hiddenValue
InBlock.gif                    : 
this.value !== undefined ? this.value : '';
InBlock.gif            
this.el.dom.removeAttribute('name');
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (Ext.isGecko) dot.gif{
InBlock.gif            
this.el.dom.setAttribute('autocomplete''off');
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.initList();
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    initList : 
function() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (!this.list) dot.gif{
InBlock.gif            
var cls = 'x-multiselectfield-list';
ExpandedSubBlockStart.gifContractedSubBlock.gif            
this.list = new Ext.Layer(dot.gif{
InBlock.gif                shadow : 
this.shadow,
InBlock.gif                cls : [cls, 
this.listClass].join(' '),
InBlock.gif                constrain : 
false
ExpandedSubBlockEnd.gif            }
);
InBlock.gif            
var lw = this.listWidth
InBlock.gif                    
|| Math.max(this.wrap.getWidth(), this.minListWidth);
InBlock.gif            
this.list.setWidth(lw);
InBlock.gif            
this.list.swallowEvent('mousewheel');
ExpandedSubBlockStart.gifContractedSubBlock.gif            
this.innerList = this.list.createChild(dot.gif{
InBlock.gif                cls : cls 
+ '-inner'
ExpandedSubBlockEnd.gif            }
);
InBlock.gif            
this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
InBlock.gif            
this.innerList.setHeight(this.layerHeight || this.minLayerHeight);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if (!this.checkpanel) dot.gif{
InBlock.gif                
this.checkpanel = this.CheckPanel(this.innerList);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
this.checkpanel.render();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    onSelect : 
function(id, text, checked) dot.gif{
InBlock.gif        
this.setValue(id, text, checked);
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    CheckPanel : 
function(el) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
var checkpanel = new Ext.Panel(dot.gif{
InBlock.gif            el : el,
InBlock.gif            autoScroll : 
true
ExpandedSubBlockEnd.gif        }
);
InBlock.gif        
var multiselectField = this;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (typeof this.contextArray != 'undefined'dot.gif{
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif            
for (var i = 0; i < this.contextArray.length; i++dot.gif{
InBlock.gif            
InBlock.gif                
var contArry = this.contextArray[i];
ExpandedSubBlockStart.gifContractedSubBlock.gif                
var auto_field = new Ext.form.Checkbox(dot.gif{
InBlock.gif                    boxLabel : contArry[
1],
InBlock.gif                    id : contArry[
0],
InBlock.gif                    name : contArry[
0],
InBlock.gif                    cls : 
'x-multiselectfield-list'
ExpandedSubBlockEnd.gif                }
);
ExpandedSubBlockStart.gifContractedSubBlock.gif                auto_field.on(
'check'function(auto_field) dot.gif{
InBlock.gif                    multiselectField.onSelect(auto_field.id,auto_field.boxLabel, auto_field.checked);
ExpandedSubBlockEnd.gif                }
);
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if(typeof this.defaltValueArray != 'undefined')dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
for (var j = 0; j < this.defaltValueArray.length; j++dot.gif{
InBlock.gif                        
var defvalArry =  this.defaltValueArray[j];
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
if(defvalArry[0]==contArry[0])dot.gif{
InBlock.gif                            auto_field.checked
=true;
ExpandedSubBlockEnd.gif                        }

ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                checkpanel.add(auto_field);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
return checkpanel
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    getValue : 
function() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (typeof this.value != 'undefined'dot.gif{
InBlock.gif            
return this.value;
ExpandedSubBlockStart.gifContractedSubBlock.gif        }
 else dot.gif{
InBlock.gif            
return Ext.form.MultiSelectField.superclass.getValue.call(this);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    setValue : 
function(id, text, ischecked) dot.gif{
InBlock.gif        
var text = text;
InBlock.gif        
var value = id;
InBlock.gif        
var return_text_string;
InBlock.gif        
var return_value_string;
InBlock.gif
InBlock.gif        
var text_temp = Ext.form.MultiSelectField.superclass.getValue.call(this);
InBlock.gif        
var ids_temp = typeof this.value != 'undefined' ? this.value : '';
InBlock.gif        
var text_arrtemp = text_temp.split(",");
InBlock.gif        
var ID_arrtemp = ids_temp.split(",");
InBlock.gif        
if(ischecked)   
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{         
InBlock.gif           text_arrtemp.push(text); 
InBlock.gif            ID_arrtemp.push(value);
ExpandedSubBlockEnd.gif        }
   
InBlock.gif        
else  
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{   
InBlock.gif            text_arrtemp.remove(text);
InBlock.gif            ID_arrtemp.remove(value);
ExpandedSubBlockEnd.gif        }
   
InBlock.gif
InBlock.gif        return_text_string 
= text_arrtemp.toString();
InBlock.gif        return_value_string 
= ID_arrtemp.toString();
InBlock.gif        
var first_text_str = return_text_string.substr(01);
InBlock.gif        
var first_value_str = return_value_string.substr(01);
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (first_text_str == ","dot.gif{
InBlock.gif            return_text_string 
= return_text_string.substr(1);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (first_value_str == ","dot.gif{
InBlock.gif            return_value_string 
= return_value_string.substr(1);
ExpandedSubBlockEnd.gif        }

InBlock.gif        Ext.form.MultiSelectField.superclass.setValue.call(
this,return_text_string);
InBlock.gif        
InBlock.gif        
this.value = return_value_string;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (this.hiddenField) dot.gif{
InBlock.gif            
this.hiddenField.value = return_value_string;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    onDestroy : 
function() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (this.list) dot.gif{
InBlock.gif            
this.list.destroy();
ExpandedSubBlockEnd.gif        }

InBlock.gif        Ext.form.MultiSelectField.superclass.onDestroy.call(
this);
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    collapseIf : 
function(e) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (!e.within(this.wrap) && !e.within(this.list)) dot.gif{
InBlock.gif            
this.collapse();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    expand : 
function() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (this.isExpanded() || !this.hasFocus) dot.gif{
InBlock.gif            
return;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.list.alignTo(this.wrap, this.listAlign);
InBlock.gif        
this.list.show();
InBlock.gif        Ext.getDoc().on(
'mousewheel'this.collapseIf, this);
InBlock.gif        Ext.getDoc().on(
'mousedown'this.collapseIf, this);
InBlock.gif        
this.fireEvent('expand'this);
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    collapse : 
function() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (!this.isExpanded()) dot.gif{
InBlock.gif            
return;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.list.hide();
InBlock.gif        Ext.getDoc().un(
'mousewheel'this.collapseIf, this);
InBlock.gif        Ext.getDoc().un(
'mousedown'this.collapseIf, this);
InBlock.gif        
this.fireEvent('collapse'this);
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    isExpanded : 
function() dot.gif{
InBlock.gif        
return this.list && this.list.isVisible();
ExpandedSubBlockEnd.gif    }
,
ExpandedSubBlockStart.gifContractedSubBlock.gif    onTriggerClick : 
function() dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (this.disabled) dot.gif{
InBlock.gif            
return;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
if (this.isExpanded()) dot.gif{
InBlock.gif            
this.collapse();
ExpandedSubBlockStart.gifContractedSubBlock.gif        }
 else dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
this.onFocus(dot.gif{});
InBlock.gif            
this.expand();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
this.el.focus();
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
);
None.gifExt.reg(
' multiselectfield ' , Ext.form.MultiSelectField);
None.gifArray.prototype.remove
= function (str)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
var tmp=this;
InBlock.gif    
for(i=0;i<tmp.length;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(tmp[i].toString()==str)dot.gif{
InBlock.gif            tmp.splice(i,
1);
InBlock.gif            
break;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值