public ActionResult GetTreeData() { DirectoryInfo dir = new DirectoryInfo("d://"); Dir dirList = GetTreeJson(dir); string json = Newtonsoft.Json.JsonConvert.SerializeObject(dirList.children); return Content(json); } private Dir GetTreeJson(DirectoryInfo dir) { Dir dirc = new Dir(); dirc.text = dir.Name; dirc.leaf = false; List<Dir> listDir = new List<Dir>(); dirc.children = listDir; FileSystemInfo[] allFile = dir.GetFileSystemInfos(); foreach (FileSystemInfo fi in allFile) { Dir d = new Dir(); d.text = fi.Name; if (fi.Attributes == FileAttributes.Directory) { d.leaf = false; listDir.Add(GetTreeJson((DirectoryInfo)fi)); } else { d.leaf = true; listDir.Add(d); } } return dirc; }
public class Dir { public string text { get; set; } public bool leaf { get; set; } public List<Dir> children { get; set; } }
VaR treeservice = new Ext. tree. treepanel ({Title: 'treepanelservice', root: {text: 'root', expanded: true}, loader: New Ext. tree. treeloader ({URL: '/home/gettreedata'}); // single table var form = new Ext. form. formpanel ({frame: True, Title: 'form title', style: 'margin: 10px ', items: [treelocal, treeservice], buttons: [{text: 'retrieve selected item', Handler: function () {selectnode = treelocal. getselectionmodel (). getselectedn Ode (); alert ('treepanellocal: '+ (selectnode = NULL? Treelocal. root. text: selectnode. text) ;}}]}); var win = new Ext. window ({Title: 'window', width: 476, height: 574, resizable: True, modal: True, closable: True, maximizable: True, minimizable: True, items: form}); win. show ();
Bind the ext tree to the local file directory