Easyui Tree 异步加载实例
生活随笔
收集整理的這篇文章主要介紹了
Easyui Tree 异步加载实例
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前臺(tái):
?
<div style="border:1px solid #ccc;width: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>?
?
?
后臺(tái):
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();}?
轉(zhuǎn)載于:https://www.cnblogs.com/shenzhenhua/p/5521481.html
總結(jié)
以上是生活随笔為你收集整理的Easyui Tree 异步加载实例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 2016年2月流量入口占比动态:搜索引擎
- 下一篇: iOS进阶(数据库之SQLite)