朋友炒股兩個月賺了10萬,我幫他推廣一下公眾號,把錢用來投資總比放銀行連通貨膨脹都跑不過里強, 硬核離職,在家炒股 ,這是他每天的日志,有些經驗是花錢也買不到的。
1.代碼如下:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title></title> 5 <!--ExtJs框架開始--> 6 <script type="text/javascript" src="/Ext/adapter/ext/ext-base.js"></script> 7 <script type="text/javascript" src="/Ext/ext-all.js"></script> 8 <link rel="stylesheet" type="text/css" href="/Ext/resources/css/ext-all.css" /> 9 <style type="text/css"> 10 .nodeicon 11 { 12 background-image: url(image/user.gif) !important; 13 } 14 </style> 15 <!--ExtJs框架結束--> 16 <script type="text/javascript"> 17 Ext.onReady(function () { 18 //樹的節點數據源 19 var node = { 20 text: '根', 21 expanded: true, 22 leaf: false, 23 children: [ 24 { text: '根下節點一[user圖標]', leaf: true, iconCls: 'nodeicon' }, 25 { text: '根下節點二', leaf: true }, 26 { text: '根下節點三', leaf: false, children: [ 27 { text: '節點三子節點一', leaf: true }, 28 { text: '節點三子節點二', leaf: false, expanded: true, children: [ 29 { text: '節點三子節點二節點一', leaf: true }, 30 { text: '節點三子節點二節點二', leaf: true } 31 ] 32 } 33 ] 34 } 35 ] 36 }; 37 //樹面板(本地數據源) 38 var treelocal = new Ext.tree.TreePanel({ 39 title: 'TreePanelLocal', 40 //rootVisible: false, 41 root: node 42 }); 43 //樹面板(服務器數據源) 44 var treeservice = new Ext.tree.TreePanel({ 45 title: 'TreePanelService', 46 root: { text: '根', expanded: true }, 47 //rootVisible: false, 48 loader: new Ext.tree.TreeLoader({ 49 url: '/App_Ashx/Demo/Tree.ashx' 50 }) 51 }); 52 //單表 53 var form = new Ext.form.FormPanel({ 54 frame: true, 55 title: '表單標題', 56 style: 'margin:10px', 57 items: [treelocal, treeservice], 58 buttons: [{ 59 text: '獲取選中項', 60 handler: function () { 61 selectNode = treelocal.getSelectionModel().getSelectedNode(); 62 alert('TreePanelLocal:' + (selectNode == null ? treelocal.root.text : selectNode.text)); 63 } 64 }] 65 }); 66 //窗體 67 var win = new Ext.Window({ 68 title: '窗口', 69 width: 476, 70 height: 574, 71 resizable: true, 72 modal: true, 73 closable: true, 74 maximizable: true, 75 minimizable: true, 76 items: form 77 }); 78 win.show(); 79 }); 80 </script> 81 </head> 82 <body> 83 <!-- 84 說明: 85 (1)var tree = new Ext.tree.TreePanel():創建一個新的TreePanel表單對象。 86 (2)root: node:根節點。 87 (3)expanded: true:是否展開子節點,默認為false,如“根下節點三”。 88 (4)leaf: true:是否為葉子節點,這個要注意下,如果設置為false但沒有 children 那么會產生一直讀取子節點的展示。 89 (5)//rootVisible: false:有時候我們不想顯示根節點,可以通過rootVisible設置他的可見性。在本例中我沒有隱藏根。 90 (6)loader: new Ext.tree.TreeLoader({ 91 url: '/App_Ashx/Demo/Tree.ashx' 92 }) 93 樹的數據載入組件,通過url尋找service端返回的json,並且自動轉換成 TreeNode。 94 (7)iconCls: 'nodeicon':ExtJs自帶的圖標顯示為“文件夾”或是“列表”,通過 iconCls 可以列換樹型菜單的圖標。 95 (8)selectNode = treelocal.getSelectionModel().getSelectedNode():獲取選中項。 96 --> 97 </body> 98 </html>
用到后台代碼如下/App_Ashx/Demo/Tree.ashx:
1 using System.Web; 2 3 namespace HZYT.ExtJs.WebSite.App_Ashx.Demo 4 { 5 public class Tree : IHttpHandler 6 { 7 public void ProcessRequest(HttpContext context) 8 { 9 string strResult = @"[ 10 { text: '根下節點一[user圖標]', leaf: true, iconCls: 'nodeicon' }, 11 { text: '根下節點二', leaf: true }, 12 { text: '根下節點三', leaf: false, children: [ 13 { text: '節點三子節點一', leaf: true }, 14 { text: '節點三子節點二', leaf: false, expanded: true, children: [ 15 { text: '節點三子節點二節點一', leaf: true }, 16 { text: '節點三子節點二節點二', leaf: true } 17 ] 18 } 19 ] 20 } 21 ]"; 22 context.Response.Write(strResult); 23 } 24 25 public bool IsReusable 26 { 27 get 28 { 29 return false; 30 } 31 } 32 } 33 }
2.效果如下:

user.gif小圖標

轉載請注明出處:http://www.cnblogs.com/iamlilinfeng
