Extjs4 实现下拉树

/*!
* @author caizhiping
* 下拉树
*/
Ext.define('keel.TreeComboBox',{
	extend : 'Ext.form.field.ComboBox',
	alias: 'widget.keeltreecombo',
	store : new Ext.data.ArrayStore({fields:[],data:[[]]}),
	editable : false,
	allowBlank:false,
	listConfig : {resizable:true,minWidth:250,maxWidth:450},
	_idValue : null,
	_txtValue : null,
	callback : Ext.emptyFn,
	treeObj : new Ext.tree.Panel({
				border : false,
				height : 250,
				//width : 350,
				autoScroll : true,
				rootVisible: false,
				store:  new Ext.data.TreeStore({
							nodeParam : 'bmjg.bmjgdm',
							proxy: {
					            type: 'ajax',
					         	url: '/fs/actions/bmjgtree!ajaxTreeforCombobox',
					            reader: 'json'
					        },
					        autoLoad : false,
					        root: {
					        	  name : 'GT',
					              id: pbmjgdm,
					              expanded: true
					        }
						})
	}),
	initComponent : function(){
		this.treeRenderId = Ext.id();
		this.tpl = "<tpl><div id='"+this.treeRenderId+"'></div></tpl>";		
		this.callParent(arguments);
		this.on({
			'expand' : function(){
			    if(!this.treeObj.rendered&&this.treeObj&&!this.readOnly){
			        Ext.defer(function(){
		        		this.treeObj.render(this.treeRenderId);
		        	},300,this);
			    }
			}
		});
		this.treeObj.on('itemclick',function(view,rec){
			if(rec){
				this.setValue(this._txtValue = rec.get('text'));
				this._idValue = rec.get('id');
				//设置回调
                this.callback.call(this,rec.get('id'), rec.get('text'));
                //关闭tree
				this.collapse();
			}
		},this);
	},
	getValue : function(){//获取id值
		return this._idValue;
	},
	getTextValue : function(){//获取text值
		return this._txtValue;
	},
	setLocalValue : function(txt,id){//设值
		this._idValue = id;
		this.setValue(this._txtValue = txt);
	}
});

 

 

调用:

 

/**下拉机构数*/
var xltree=new keel.TreeComboBox({
    fieldLabel : '部门机构',
    name:'BMJGJC',
    anchor:'95%',
    //allowBlank:false,
    callback:function(id,text){
    	    //赋值给隐藏域
    		T_RY_NEW_FORM.getForm().findField("BMJGDM").setValue(id);
    }
}); 

 

效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值