EXTJs 树的实现

[javascript]  view plain copy
  1. <script type="text/javascript">  
  2.         Ext.onReady(function()  
  3.             {  
  4.                 //树形结构  
  5.                 //创建一棵树:  
  6.                 var tree = new Ext.tree.TreePanel(  
  7.                     {el:'tree'}//表示渲染的DOM的id.界面中有<div id = "tree"></div>相对应最后这棵树就出现在这个div位置上  
  8.                 );  
  9.                 //创建根节点:  
  10.                 var root = new Ext.tree.TreeNode({text:'山东'});  
  11.                 tree.setRootNode(root);//把根节点添加到树中  
  12.                 tree.render();//对树进行渲染   
  13.                 //添加枝叶  
  14.                 var node1 = new Ext.tree.TreeNode({text:'济南'});  
  15.                 var node11 = new Ext.tree.TreeNode({text:'市中区'});  
  16.                 var node12 = new Ext.tree.TreeNode({text:'章丘市'});  
  17.                 var node2 = new Ext.tree.TreeNode({text:'青岛'});  
  18.                 var node21 = new Ext.tree.TreeNode({text:'黄岛区'});  
  19.                 var node22 = new Ext.tree.TreeNode({text:'城阳区'});  
  20.                 var node3 = new Ext.tree.TreeNode({text:'淄博'});  
  21.                 var node31 = new Ext.tree.TreeNode({text:'沂源'});  
  22.                 var node32 = new Ext.tree.TreeNode({text:'张店'});  
  23.                 var node33 = new Ext.tree.TreeNode({text:'博山'});  
  24.                   
  25.                 root.appendChild(node1);  
  26.                 root.appendChild(node2);  
  27.                 root.appendChild(node3);  
  28.                   
  29.                 node1.appendChild(node11);  
  30.                 node1.appendChild(node12);  
  31.                   
  32.                 node2.appendChild(node21);  
  33.                 node2.appendChild(node22);  
  34.                   
  35.                 node3.appendChild(node31);  
  36.                 node3.appendChild(node32);  
  37.                 node3.appendChild(node33);  
  38.                   
  39.                 root.expand(true,true);//加载后立即展开树  
  40.             }  
  41.         );  
  42.     </script>  

EXTJs 树的实现_第1张图片


使用TreeLoader加载数据:

你可能感兴趣的:(EXTJs 树的实现)