Extjs4 TreePanel实例

随着Extjs4第五预览版的发布,更多的实例被放了出来,本文介绍Extjs4 TreePanel的使用。此实例来自Extjs官方网站,此实例并没有限制树节点的拖放,例子中使用了TreeStore 和 AjaxProxy

HTML代码:

 
  1. <div id="tree-div" style="width:250px;border:1px solid #c3daf9;"></div>

JS代码:

 
  1. Ext.require([
  2.     'Ext.tree.*',
  3.     'Ext.data.*'
  4. ]);
  5. Ext.onReady(function() {    
  6.     var store = new Ext.data.TreeStore({
  7.         proxy: {
  8.             type: 'ajax',
  9.             url: 'get-nodes.php'
  10.         },
  11.         root: {
  12.             text: 'Ext JS',
  13.             id: 'src',
  14.             expanded: true
  15.         },
  16.         sorters: [{
  17.             property: 'leaf',
  18.             direction: 'ASC'
  19.         }, {
  20.             property: 'fileName',
  21.             direction: 'ASC'
  22.         }]
  23.     });
  24.     
  25.     var tree = new Ext.tree.TreePanel({
  26.         //autoScroll: true,
  27.         //enableDD: true,
  28.         //containerScroll: true,
  29.         animate: true,
  30.         border: false,
  31.         store: store,
  32.         viewConfig: {plugins: [{ptype: 'treeviewdd'}]},
  33.         renderTo: 'tree-div',
  34.         height: 300
  35.     });
  36. });

例子中返回的数据为JSON格式,要求服务端可以返回类似如下的数据:

 
  1. [{"text":"layout","id":"src\/layout","cls":"folder"},{"text":"ComponentQuery.js","id":"src\/ComponentQuery.js","leaf":true,"cls":"file"},{"text":"draw","id":"src\/draw","cls":"folder"}]

 

你可能感兴趣的:(Ajax,function,layout,ExtJs,border,plugins)