easyui tree动态传参实现异步加载不同数据源

来源:互联网 发布:修改qq农场数据 编辑:程序博客网 时间:2024/05/03 03:11

视图中:

<script>    var treeInfo;    $(document).ready(function () {        treeInfo = $('#treeInfo');        getTree();    });    function getTree() {        treeInfo.tree({            url: "/Criteria/ListTree",            queryParams: { },            onBeforeLoad: function (node, param) {                if (node) {                    param.type = node.tag;                    param.root = node.isroot;                }            }        });    }</script><ul id="treeInfo"></ul>

控制器中:

        [HttpPost]        [Description("总览树")]        public JsonResult ListTree()        {            if (Request.Form["id"] == null)            {                #region  初始树                DataTable dt = new OverViewImpl().GetInitTree();                List<object> list = new List<object>();                Hashtable hsInfo = new Hashtable();                hsInfo.Add("id", "info");                hsInfo.Add("text", "数据集");                hsInfo.Add("state", "open");                Hashtable hsCode = new Hashtable();                hsCode.Add("id", "code");                hsCode.Add("text", "代码集");                hsCode.Add("state", "open");                List<object> listInfo = new List<object>();                List<object> listCode = new List<object>();                foreach (DataRow dr in dt.Rows)                {                    string type = dr["type"].ToString();                    int count = int.Parse(dr["nums"].ToString());                    string state = count > 0 ? "closed" : "open";                    Hashtable hs = new Hashtable();                    hs.Add("id", dr["id"]);                    hs.Add("text", dr["name"].ToString()+"("+count.ToString()+")");                    hs.Add("state", state);                    hs.Add("tag", type);                    if (type == "info")                    {                        listInfo.Add(hs);                    }                    else if (type == "code")                    {                        listCode.Add(hs);                    }                }                hsInfo.Add("children", listInfo);                hsCode.Add("children", listCode);                list.Add(hsInfo);                list.Add(hsCode);                return Json(list);                #endregion            }            else            {                string id = Request.Form["id"];                string type = Request.Form["type"];                //在此可以根据type从不同的表获取数据源                List<object> list = new List<object>();                Hashtable hs = new Hashtable();                hs.Add("id", "ddd");                hs.Add("text", "测试");                hs.Add("tag", type);                hs.Add("state", "open");                list.Add(hs);                return Json(list);            }        }

实现目的:在树中异步加载不同数据源。

1 0
原创粉丝点击