easyUI 异步加载树
$(function () { var selected = $('#depttree').tree('getSelected'); $('#depttree').tree({ checkbox: false, animate: true, url: '/Provider/HandlerCommon.ashx?method=getsessiontree', onClick: function (node) { }, onSelect: function (node) { // deptid = node.id; }, onExpand: function (node) { // expandid = node.id; }, onLoadSuccess: function (row, data) { } }); });
private string GetSessionTree(HttpContext context) { string parentid = context.Request["id"] == null ? "000" : context.Request["id"]; StringBuilder sb = new StringBuilder(); sb.Append("["); if (parentid.Length == 9) { DataCondition<EntitySequenceDepartment.Field> conditsequencedepartment = new DataCondition<EntitySequenceDepartment.Field>(); conditsequencedepartment.Add("{0}='" + parentid + "'",EntitySequenceDepartment.Field.Sequence_Cur); IList<EntitySequenceDepartment> SequenceDepartmentList = DbSequenceDepartment .ListView(conditsequencedepartment); for (int i = 0; i < SequenceDepartmentList.Count; i++) { sb.Append("{\"id\":\"" + SequenceDepartmentList[i].Sequence_Cur + "\","); sb.Append("\"text\":\"" + SequenceDepartmentList[i].DepartmentName + "\","); sb.Append("\"attributes\":\"" + SequenceDepartmentList[i].SeDepartment_Id + "\","); sb.Append("\"state\":\"open\" },"); } } else { DataCondition<EntitySequence.Field> conditionchild = new DataCondition<EntitySequence.Field>(); conditionchild.Add("{0}='" + parentid + "'", EntitySequence.Field.Sequence_Parent); IList<EntitySequence> SequenceList = DbSequence.ListView(conditionchild); for (int i = 0; i < SequenceList.Count; i++) { sb.Append("{\"id\":\"" + SequenceList[i].Sequence_Cur + "\","); sb.Append("\"text\":\"" + SequenceList[i].Sequence_Name + "\","); sb.Append("\"attributes\":\"" + SequenceList[i].Sequence_Id + "\","); if (CheckSequence(SequenceList[i].Sequence_Cur)) { sb.Append("\"state\":\"closed\" },"); } else { if (CheckSequenceDepartment(SequenceList[i].Sequence_Cur)) { sb.Append("\"state\":\"closed\" },"); } else { sb.Append("\"state\":\"open\" },"); } } } } sb.Remove(sb.Length - 1, 1); sb.Append("]"); return sb.ToString(); }