JS Section
<Br/>/** <br/> tree demo 1 asynchronous tree <br/> composition: <br/> 1. node <br/>. common node <br/> B. root node <br/> C. default attribute ID text leaf children icon <br/> 2 .. tree loader <br/> 3. tree container <br/> 4. event <br/> 5. rendering <br/> **/<br/> Ext. onready (function () {<br/> var combohidden = new Ext. form. hidden ({<br/> name: 'combohidden ', <br/> value: ''<br/>}); <br/> var comboxwithtree = new Ext. form. comboBox ({<br/> store: New Ext. data. simplestore ({fields: [], data: [[]}), <br/> Editable: false, <br/> mode: 'local ', <br/> triggeraction: 'all', <br/> maxheight: 200, <br/> Height: 500, <br/> TPL: "<Div id = 'tree'> </div>", <br/> selectedclass: '', <br/> value:'', <br/> onselect: ext. emptyfn <br/>}); <br/> comboxwithtree. render ('comboxwithtree '); <br/> var oproot = new Ext. tree. asynctreenode ({<br/> ID: '1', <br/> text: 'root' <br/> }); <br/> // loader for communication with the background <br/> var loader = new Ext. tree. treeloader ({<br/> dataurl: 'exttree. php', <br/> baseparams: {<br/> method: 'gettree', <br/> PID: ''<br/>}< br/> }); <br/> // tree container <br/> var optree = new Ext. tree. treepanel ({<br/> anchor: '000000', <br/> frame: false, <br/> width: 95%, <br/> Height: 200, <br/> Animate: false, <br/> rootvisible: True, <br/> autoscroll: True, <br/> Loader: loader, // The loader defined earlier <br/> root: oproot // The root node defined earlier <br/> }); <br/> // load the previously triggered event <br/> optree. loader. on ("beforeload", function (treeloader, node) {<br/> loader. baseparams. PID = node. attributes. ID; <br/>}); <br/> // Tree node click event <br/> optree. on ('click', function (node, event) {<br/> If (node. isleaf () {<br/> event. stopevent (); <br/> comboxwithtree. setvalue (node. attributes. text); <br/> combohidden. setvalue (node. attributes. ID); <br/> comboxwithtree. collapse (); </P> <p> Ext. MSG. show ({<br/> title: 'hs', <br/> MSG: "You clicked: <br/> node -- "+ node <br/> +" <br/> node.attributes.tar get -- "+ node.attributes.tar get <br/> +" <br/> combohidden. getvalue () -- "+ combohidden. getvalue (), <br/> animel: node. UI. textnode <br/>}); <br/>}else {<br/> event. stopevent (); <br/> node. toggle (); // click it to expand or close the subnode <br/>}< br/>}); <br/> comboxwithtree. on ('expand', function () {<br/> optree. render ('tree'); <br/> optree. root. reload (); <br/>}); <br/>
HTML section
<Div id = 'comboxwithtree '> </div>
PHP part. The database interaction process is omitted here, and background data is simulated through arrays.
################################# Exttree. php:
<Br/> $ record = array (<br/> array ("ID" => "5", "name" => "A02 ", "target" => "category") <br/>, array ("ID" => "11", "name" => "A03 ", "target" => "") <br/>, array ("ID" => "15", "name" => "a04 ", "target" => "region") <br/>); </P> <p> $ jsonret = "["; <br/> foreach ($ record as $ key => $ value) {<br/> if ($ totalrecord [0] ["Total"]> 0) {<br/> $ ifleaf = "false"; <br/>}else {<br/> $ ifleaf = "true "; <br/>}< br/>/* pass custom attributes, value of a single field */<br/> $ jsonret. = "{<br/> ID: '{$ value [" ID "]}' <br/>, text: '{$ value ["name"]}' <br/>, leaf: {$ ifleaf} <br/>, target: '{$ value ["target"]}' <br/>}, "; <br/>}< br/> $ jsonret = trim ($ jsonret ,", "); <br/> $ jsonret. = "]"; <br/> @ header ("Content-Type: text/html; charset = UTF-8"); <br/> exit ($ jsonret );