首页 > 代码库 > 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 树 绑定本地文件目录