<script> Ext.onReady(function(){ var root=new Ext.tree.AsyncTreeNode({ id:'0', text:'所有分类' }); var data=new Ext.tree.TreeLoader({url:'_tree_json.php'}); var tree=new Ext.tree.TreePanel({ renderTo:'test', root:root, loader:data, width:300 }); data.on('beforeload',function(treeLoader,node){ this.baseParams.id=node.attributes.id; },data); }); </script> <div id="test"></div> 服务端的php代码: <?php require("conn.php"); $father_id=$_POST['id']; function _count($father_id){ $count_req=mysql_query("select count(id) as count from kind where father_id=$father_id"); $count_num=mysql_fetch_array($count_req); return $count_num['count']; } $count=_count($father_id); $return=mysql_query("select * from kind where father_id=$father_id"); echo "["; $i=1; while ($req=mysql_fetch_array($return)) { $id=$req['id']; $name=$req['name']; if (_count($id)>0) { echo "{ id: $id, text: '$name', leaf: false }"; }else { echo "{ id: $id, text: '$name', leaf: true }"; } if ($i<$count) { echo ","; } $i++; } echo "]"; ?> ext异步加载树的子节点