1.extjs4.0api is very much different than 3.0.
2. Select and expand the multi-level child parent node.
3. Reload the data. Tree.getstore (). Load
4. Remove the node, get the Node Tree.getstore () from the tree based on the ID. Getnodebyid ();
5. Get the selected node, Tree.getview (). getchecked ();
6. Data for asynchronous loading, set node selection, Tree.getstore (). Getnodebyid ("). Set ({checked:true});
<script type= "Text/javascript" >Ext.require ([' Ext.tree.* ', ' Ext.data.* ', ' Ext.window.MessageBox ', ' Ext.tip.* ' ]); Ext.onready (function() {/** You can get the ID of the selected node, and the text **/varCheckednodes ={_data:{}, update:function(id,text,checked) {if(checked) { This. Add (id,text,checked); }Else if(!checked) { This. Delbyid (ID); }}, add:function(id,text) {if(! This. _data[id]) { This. _data[id] = {' id ': ID, ' text ': text}; }}, Delbyid:function(ID) {if( This. _data[id]) { Delete This. _data[id]; }}, GetById:function(ID) {return This. _data[id]; }, JoinId:function(Sep) {arr= []; for(IDinch This. _data) {Arr.push (ID); } returnArr.join (Sep); }, Joinname:function(Sep) {arr= []; for(IDinch This. _data) {Arr.push ( This. _data[id].text); } returnarr.join (Sep)}, contains:function(ID) {returnThis_data[id]; }, Init:function(ids,texts) {if(IDs. IndexOf (', ') > 1) {Idarr= Ids.split (', '); Textarr= Texts.splist (', '); for(vari=0; i<idarr.length; i++){ if(Idarr[i].replace (/^\s+|\s+$/g, ')! = "){ This. Add (Idarr[i],textarr[i]); } } } }}; Ext.define (' OrgInfo ', {extend: ' Ext.data.Model ', fields: [{name:' ID '}, {name:' Text '}, {name:' Name '} ] }); varOrgstore = ext.create (' Ext.data.TreeStore '), {defaultrootid:"10", Model:"OrgInfo", Root: {ID:10,text: ' Shun Fung Express Group ', Leaf:false}, Proxy: {type:' Ajax ', Actionmethods: ' POST ', url: ' tree_data.jsp ', Reader:{type: ' JSON '}}, Nodeparam:' ID ', TextField:"Name" }); /** Set child node or parent node selected method * Set the method selected by the individual node*/ varTreenodecheck ={setnodechecked:function(node,checked) {checkednodes.update (Node.get (' id '), node.get (' text '), checked); Node.set (' Checked ', checked); }, childchecked:function(node,checked) {treenodecheck.setnodechecked (node,checked); Node.expand (); if(Node.haschildnodes ()) {Node.eachchild (function(Child) {treenodecheck.childchecked (child,checked); }); }}, parentchecked:function(node,checked) {varParentNode =Node.parentnode; Checked= ParentNode = =NULL?NULL: checked; Treenodecheck.setnodechecked (node,checked); //Set Parent node unchecked if(ParentNode! =NULL){//Expand if the parent node is not empty varFlag =false; Parentnode.eachchild (function(child) {if(child.data.checked = =true) {flag=true; } }); if(Checked = =false){ if(!flag) {treenodecheck.parentchecked (parentnode,checked); } }Else{ if(flag) {treenodecheck.parentchecked (parentnode,checked); } } } } }; Ext.define ("Orgtreepanel", {extend:"Ext.tree.Panel", Store:orgstore, rootvisible:true, Usearrows:true, Frame:true, Title:' Check Tree ', Width:200, Height:250, padding:' 0 0 0 0 ', Selectids:function(){ varRecords = This. GetView (). getchecked (), IDs= []; Ext.Array.each (Records,function(REC) {Ids.push (Rec.get (' ID ')); }); returnIds.join (","); }, listeners:{Checkchange:function(node,checked,eopts) {treenodecheck.childchecked (node,checked); Treenodecheck.parentchecked (node,checked); }, Load:function(store, records, successful, operation, eopts) {if(records.data.checked!=NULL){ varhaschecked =false; Ext.Array.each (Successful,function(rec) {if(rec.data.checked) {haschecked=true; return false; } }); if(!records.data.checked) { if(haschecked) {Ext.Array.each (successful,function(REC) {treenodecheck.childchecked (REC,false); }); } }Else{ if(!haschecked) {Ext.Array.each (successful,function(REC) {treenodecheck.childchecked (REC,true); }); } } } } } }); varWin =NULL; varTree =NULL; Ext.create (' Ext.button ', {text:' Get the selected node ', RenderTo:Ext.getBody (), Handler:function() {Console.info (Ext.isempty (‘ ‘)); Console.info ("Checkednodes.joinid:" +checkednodes.joinid ("-")); } }); Ext.create (' Ext.button ', {text:' Delete Tree ', RenderTo:Ext.getBody (), Handler:function() {Tree.getrootnode (). RemoveAll (false); Tree.getstore (). Load (); } }); Win= Ext.create (' Ext.window.Window ', {title:' Hello ', Height:250, Width:400, layout:' Fit ', Closeaction:' Hide ', Showwin:function(){ This. Show (); Tree.getrootnode (). RemoveAll (false); Tree.getstore (). Load ({scope: This, Callback:function(Records, operation, success) {if(!Tree.getrootnode (). isexpanded ()) {Tree.getrootnode (). expand (); } } }); }, InitComponent:function() {//constructor Function varme = This; Tree= Ext.create ("Orgtreepanel"); Me.items=[tree]; Me.superclass.initComponent.call (Me); }, listeners: {beforehide:function(Win, eopts) {}}}); Ext.create (' Ext.button ', {text:' Click me ', RenderTo:Ext.getBody (), Handler:function() {Win.showwin (); } });});</script>
extjs4.0 treepanel node selection, expand! Reloading of data