资源描述:
《Extjs自定义组件-下拉树》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Ext-下拉树效果图:使用方式:1、前台:xtype:'mycomboxtree',url:'Dep.queryDep.do',fieldLabel:'报销单位',treeRootText:'所有单位',//根节点名称//rootVisible:false,//是否显示根节点allowUnLeafClick:false//false表示不允许非子叶点击选中。2、action:StringfatherId=request.getParameter("id");Listlist=this.depService.queryDep(Integer.parseInt(fatherId));
2、Strings="[";for(Depd:list){s=s+"{'text':'"+d.getName()+"','id':'"+d.getId()+"'";if(!this.depService.checkHasChild(d.getId())){s=s+",'leaf':"+true+"},";}else{s=s+"},";}}s=s.substring(0,s.length()-1)+"]";response.getWriter().write(s);1、组件原件ComboboxTree=Ext.extend(Ext.form.ComboBox,{id:'',//选填url:'',
3、//必填fieldLabel:'下拉树',//选填name:'',treeRootText:'所有',rootVisible:true,//是否显示根节点allowUnLeafClick:false,//false表示不允许非子叶点击选中。/******以上为必填或者选填项*******/store:newExt.data.SimpleStore({fields:[],data:[[]]}),editable:false,autoScroll:false,mode:'local',triggerAction:'all',emptyText:'请选择...',width:150,tpl:"<
4、divid='tree'>
",selectedClass:'',onSelect:Ext.emptyFn,initComponent:function(){ComboboxTree.superclass.initComponent.call(this);/***therootofopTree;*/this.opRoot=newExt.tree.AsyncTreeNode({id:'0',text:this.treeRootText});/***与后台通讯的加载器*/this.loader=newExt.tree.TreeLoader({url:this.url,listener
5、s:{"beforeload":function(treeloader,node){treeloader.baseParams={id:node.id};}}});/***theopTreeusedtochoosethedep;*/this.tree=newExt.tree.TreePanel({anchor:'95%',frame:false,width:this.width-5,height:150,animate:false,rootVisible:this.rootVisible,autoScroll:true,loader:this.loader,root:this.opRoot
6、});this.comboHidden=newExt.form.Hidden({id:'comboHidden',name:'hidden',value:''})},/***----------------------------------*树的单击事件处理*@paramnode,event*----------------------------------*/treeClk:function(node,e){if(!node.isLeaf()&&!this.allowUnLeafClick){e.stopEvent();//非叶子节点则不触发return;}if(node.id=='
7、0'){return;}this.setValue(node.text);//设置option值this.comboHidden.setValue(node.id);//设置隐藏域值this.collapse();//隐藏option列表},reset:function(){this.setValue();//重置this.comboHidden.setValue();//重置隐藏域值},//自定义方法,去的隐藏域值ge