zoukankan      html  css  js  c++  java
  • Easyui Tree 异步加载实例

    前台:

       <div style="border:1px solid #ccc;100px;padding:10px">
            <ul id="MyTree"></ul>  
        </div>
        <button onclick="getChecked()">获得选中值</button>
        <script type="text/javascript">
            $('#MyTree').tree({
                url: 'tree.ashx?id=0&state=closed',
                checkbox: true,
                onBeforeExpand: function (node, param) {
                     $(this).tree('options').url = "tree.ashx?state=open&id=" + node.id;
                }
            });
    
            function getChecked() {
                var arr = [];
                var nodes = $('#MyTree').tree('getChecked', 'checked');
                for (var i = 0; i < nodes.length; i++) {
                    arr.push(nodes[i].id);
                }
                alert(arr.join(','));
            }
        </script>

    后台:

                string id = context.Request["id"];
                string state = context.Request["state"];
    
                string json = EasyuiHelper.GetTreeJson(dt,Convert.ToInt32(id) , "linkageid","name", "parentid", state);
                
                context.Response.ContentType = "text/plain";
                context.Response.Write(json);
         
       public static string GetTreeJson(DataTable dt, int RootId, string IdFieldName, string TextFieldName,string ParentRelationFieldName, string state = "open")
            {
                StringBuilder json = new StringBuilder();
                json.Append("[");
                int i = 0;
                foreach (DataRow row in dt.Rows)
                {
                    if (Convert.ToInt32(row[ParentRelationFieldName].ToString()) == RootId)
                    {
                        json.Append("{");
                        json.Append(""id":" + row[IdFieldName].ToString());
                        json.Append(","text":"" + row[TextFieldName].ToString() + """);
                        json.Append(string.Format(","state":"{0}"", state));
                        if (state == "open")
                        {
                            string ChildrenNode = GetTreeJson(dt, Convert.ToInt32(row[IdFieldName].ToString()), IdFieldName, TextFieldName, ParentRelationFieldName, state);
                            if (ChildrenNode != "[]")
                            {
                                json.Append(","children":" + ChildrenNode);
                            }
                        }
                        json.Append("},");  
                    }
                  
                }
                if (json.ToString().EndsWith(","))
                {
                    json.Remove(json.Length - 1, 1);
                }
                json.Append("]");
                return json.ToString();
            }
  • 相关阅读:
    java8
    Python isinstance()
    Python3 File next()
    np.array() 与 np.mat() 比较
    np.nonzero()
    np.dot()
    算法之归并排序的应用 —— 小和问题以及逆序对问题
    递归过程以及递归master公式
    算法之异或运算及其应用
    算法之二分法及其应用
  • 原文地址:https://www.cnblogs.com/southhuachen/p/5521481.html
Copyright © 2011-2022 走看看