資源描述:
《Extjs自定義組件-下拉樹》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、Ext-下拉樹效果圖:使用方式:1、前臺(tái):xtype:'mycomboxtree',url:'Dep.queryDep.do',fieldLabel:'報(bào)銷單位',treeRootText:'所有單位',//根節(jié)點(diǎn)名稱//rootVisible:false,//是否顯示根節(jié)點(diǎn)allowUnLeafClick:false//false表示不允許非子葉點(diǎn)擊選中。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,//是否顯示根節(jié)點(diǎn)allowUnLeafClick:false,//false表示不允許非子葉點(diǎn)擊選中。/******以上為必填或者選填項(xiàng)*******/store:newExt.data.SimpleStore({fields:[],data:[[]]}),editable:false,autoScroll:false,mode:'local',triggerAction:'all',emptyText:'請(qǐng)選擇...',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});/***與后臺(tái)通訊的加載器*/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();//非葉子節(jié)點(diǎn)則不觸發(fā)return;}if(node.id=='
7、0'){return;}this.setValue(node.text);//設(shè)置option值this.comboHidden.setValue(node.id);//設(shè)置隱藏域值this.collapse();//隱藏option列表},reset:function(){this.setValue();//重置this.comboHidden.setValue();//重置隱藏域值},//自定義方法,去的隱藏域值ge