Ext.onReady( function() { var viewport = new Ext.tree.TreePanel( { title : "系統相關", width : 200, height : 500, rootVisible : true,//root結點顯不顯示 root : new Ext.tree.AsyncTreeNode( { text : '根', id:'r', children : [ { text : '個人資料', id:'c1', children : [ { text : '個人資料維護', id:'c1c1', leaf : true }, { text : '密碼變更', myid:'c1c2', leaf : true } ] }, { text : '客戶資料', id:'c2', children : [ { text : '客戶基本資料查詢維護', leaf : true, id:'c2c1' }, { text : '客戶基本資料列印', leaf : true, id:'c2c2' } ] } ] }) }); viewport.render('toolbar'); viewport.doLayout(); var btn=new Ext.Button({ renderTo:"btn", id:'test', text:'test', handler:function(){ viewport.selectPath('/r/c2/c2c1'); alert(viewport.root.findChild( 'id', 'c1c1', true )); viewport.expandPath('/r/c1/c1c1'); alert(viewport.root.findChild( 'id', 'c1c1', true )); viewport.root.findChild( 'id', 'c1c1', true ).select(); alert("wait3"); viewport.root.findChild( 'myid', 'c1c2', true ).select(); } }); });
<!doctype html> <html> <head> <title>MessageBox</title> <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.4.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="http://extjs.cachefly.net/ext-3.4.0/ext-all.js"></script> <link href="http://extjs.cachefly.net/ext-3.4.0/resources/css/ext-all.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="toolbar" /> <div id="btn" /> </body> </html>