现在的位置: 首页 > 综合 > 正文

extjs4.0 动态异步加载节点数据

2013年05月04日 ⁄ 综合 ⁄ 共 1833字 ⁄ 字号 评论关闭

直接上代码!

样例1:传统的树形

[javascript]
view plain
copy
  1. var store2 = Ext.create('Ext.data.TreeStore', {  
  2.         proxy: {  
  3.             type: 'ajax',  
  4.             url: 'WebForm1.aspx'  
  5.         },  
  6.         fields:['id','text']//跟旧版本extjs一样,节点的id和显示文本  
  7.     });  
  8.       
  9. var AsyncTree2 = Ext.create("Ext.tree.Panel",{  
  10.         title: 'Simple Tree2',  
  11.         width:300,  
  12.         height:500,  
  13.         collapsible: true,  
  14.         singleExpand: true,  
  15.         root: {  
  16.             id:1,  
  17.             text: "Root node",  
  18.             expanded: true  
  19.           
  20.         },  
  21.     store:store2,  
  22.     renderTo:  Ext.getBody()  
  23. });  

样例2:TreeGrid

[javascript]
view plain
copy
  1. var store = Ext.create('Ext.data.TreeStore', {  
  2.         proxy: {  
  3.             type: 'ajax',  
  4.             url: 'WebForm1.aspx'  
  5.         },  
  6.         fields:['projectId','project','taskId','id','text']  
  7.     });  
  8.       
  9.     var AsyncTree = Ext.create("Ext.tree.Panel",{  
  10.         title: 'Simple Tree',  
  11.         width:300,  
  12.         height:500,  
  13.         collapsible: true,  
  14.         useArrows: true,  
  15.         multiSelect: true,  
  16.         //singleExpand: true,  
  17.         root: {  
  18.             id:1,  
  19.             text: "Root node",  
  20.             expanded: true  
  21.           
  22.         },  
  23.     columns:[  
  24.         { xtype: 'treecolumn', text:'text',dataIndex:'taskId'},//要标明为treecolumn,否则显示不出节点前面的小图标  
  25.           
  26.         {text:'ParentId',dataIndex:'projectId'}//第二列  
  27.     ],  
  28.     store:store,  
  29.     renderTo: Ext.getBody()  
  30.   
  31.     });  

当首次点击子节点时,会Post一个参数node(节点的id值)到后台服务器,用Firebug可以临看到。

WebForm1.aspx返回的JSON样例(根据实际应用组织)

[{projectId: 100, text: 'G112', taskId: 112,  estimate: 6, rate: 150, due:'06/24/2007',checked:true},
	    {projectId: 100, text: 'A113', id: 113,  estimate: 4, rate: 150, due:'06/25/2007',leaf:true},
	    {projectId: 100, text: 'V114', id: 114,  estimate: 4, rate: 150, due:'06/27/2007'},
	    {projectId: 100, text: 'C115', id: 115,  rate: 0, due:'06/29/2007'}]

抱歉!评论已关闭.