public JsonResult NodeList() {
OperateResult result = new OperateResult();
LinkedList> FirstLLD = new LinkedList>();
DictionaryFirstMap; LinkedList> SecondLLD;
DictionarySecondMap; LinkedList> ThirdLLD; DictionaryThirdMap; var MenuList = db.Menu.Where(a => a.Pid == 0).ToList();//一级 foreach (var item in MenuList) { FirstMap = new Dictionary(); FirstMap.Add("MenuID", item.MenuID); FirstMap.Add("MenuName", item.Name); var SecondList=db.Menu.Where(a => a.Pid == item.MenuID).ToList();//二级 SecondLLD = new LinkedList>(); foreach (var items in SecondList) { SecondMap = new Dictionary(); SecondMap.Add("MenuID", items.MenuID); SecondMap.Add("MenuName", items.Name); SecondLLD.AddLast(SecondMap); var ThirdList = db.Node.Where(a=>a.NodeID==items.NodeID).ToList();//三级 ThirdLLD = new LinkedList>(); foreach (var itemes in ThirdList) { ThirdMap = new Dictionary {
{ "NodeID", itemes.NodeID },
{ "NodeName", itemes.Name }
};
ThirdLLD.AddLast(ThirdMap);
}
SecondMap.Add("children", ThirdLLD);
}
FirstMap.Add("children", SecondLLD);
FirstLLD.AddLast(FirstMap);
}
return Json(FirstLLD);
}
网友评论