码迷,mamicode.com
首页 > 其他好文 > 详细

Ext 树 绑定本地文件目录

时间:2014-09-22 20:48:03      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   文件   div   

        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 树 绑定本地文件目录

标签:style   blog   color   io   os   ar   for   文件   div   

原文地址:http://www.cnblogs.com/zhushangwei/p/3986629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!