首页 > 代码库 > Ext 树 绑定本地文件目录
Ext 树 绑定本地文件目录
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: ‘根‘, expanded: true }, loader: new Ext.tree.TreeLoader({ url: ‘/home/GetTreeData‘ }) }); //单表 var form = new Ext.form.FormPanel({ frame: true, title: ‘表单标题‘, style: ‘margin:10px‘, items: [treelocal, treeservice], buttons: [{ text: ‘获取选中项‘, handler: function() { selectNode = treelocal.getSelectionModel().getSelectedNode(); alert(‘TreePanelLocal:‘ + (selectNode == null ? treelocal.root.text : selectNode.text)); } }] }); var win = new Ext.Window({ title: ‘窗口‘, width: 476, height: 574, resizable: true, modal: true, closable: true, maximizable: true, minimizable: true, items: form }); win.show();
Ext 树 绑定本地文件目录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。