漂亮的树Tree控件代码

Ext.TreeComboField=Ext.extend(Ext.form.TriggerField,{      
valueField:"id",
displayField:"name",
haveShow:false,
editable:false,
onTriggerClick : function(){
if(!this.tree.rendered)
{
this.treeId = Ext.id();
panel.id = this.treeId;
this.getEl().dom.parentNode.appendChild(panel);
this.tree.render(this.treeId);
this.tree.setWidth(this.width);
this.tree.getEl().alignTo(this.getEl(), "tl-bl");
}
this.tree.show();
},
initComponent : function(){
Ext.TreeComboField.superclass.initComponent.call(this);

},
onRender : function(ct, position){
Ext.TreeComboField.superclass.onRender.call(this, ct, position);
this.tree.on("click",this.choice,this);
if(this.hiddenName){
this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
'before', true);
this.hiddenField.value =
this.hiddenValue !== undefined ? this.hiddenValue :this.value !== undefined ? this.value : '';
this.el.dom.removeAttribute('name');
}
if(!this.editable){
this.editable = true;
this.setEditable(false);
}
},
getValue : function(){
return typeof this.value != 'undefined' ? this.value : '';
},
clearValue : function(){
if(this.hiddenField){
this.hiddenField.value = '';
}
this.setRawValue('');
this.lastSelectionText = '';
this.applyEmptyText();
},
readPropertyValue:function(obj,p)
{
var v=null;
for(var o in obj)
{
if(o==p)v=obj[o];
}
return v;
},
setValue : function(obj){
if(!obj){
this.clearValue();
return;
}
var v=obj;
var text = v;
var value=this.valueField||this.displayField;
if(typeof v=="object" && this.readPropertyValue(obj,value)){
text=obj[this.displayField||this.valueField];
v=obj[value];
}
var node = this.tree.getNodeById(v);
if(node){
text = node.text;
}else if(this.valueNotFoundText !== undefined){
text = this.valueNotFoundText;
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = v;
}
Ext.TreeComboField.superclass.setValue.call(this, text);
this.value = v;
},
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');
}
},
choice:function(node,eventObject)
{
if(node.id!="root") this.setValue(node.id);
else this.clearValue();
this.tree.hide();
},
onDestroy : function(){
if(this.tree.rendered){
this.tree.getEl().remove();
}
Ext.TreeComboField.superclass.onDestroy.call(this);
}
});
Ext.reg('treecombo', Ext.TreeComboField);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值