Bind the ext tree to the local file directory

Source: Internet
Author: User
        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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.