/// <summary> /// 递归初始化持久化内容 /// </summary> private void InitPersistKey(JObject jobject, int year) { //1、遍历所有的子菜单,找到匹配的展开项 //2、加载展开项的子菜单,从匹配列表中移除已加载的展开项 //3、重新执行 1~2 //AllCategories. foreach (JObject jCate in jobject["children"]) { if (_expandedKeys.Count == 0) { break; } var matchedExpandedKey = _expandedKeys.FirstOrDefault(p => p == jCate["key"].ToString()); if (matchedExpandedKey != null) { jCate["children"] = new JArray( AllDepts.Where(m => m.DepartmentType == (int)jCate["key"] && m.RegYear == year) .OrderBy(p => p.OrderNum) .ThenBy(p => p.ID) .Select(ParseDeptJObject)); _expandedKeys.Remove(matchedExpandedKey); } } }
private string GetChildren(int deptType, int year) { var children = AllDepts.Where(p => p.DepartmentType == deptType && p.RegYear == year) .OrderBy(p => p.OrderNum) .ThenBy(p => p.ID); var jArray = new JArray(children.Select(ParseDeptJObject)); return(jArray.ToString()); }